InsertJSONStructure: booleans
Posted: Tue Oct 04, 2016 10:32 am
At the moment we cannot specify values as boolean when added to a JSON object using InsertJSONStructure() as they are always added as integer values
Suggestions:
1) new data type: boolean which has an integer range of 0 to 1 (ie false, true). Thus functions would know when to convert a value to boolean implicitely. Not sure how massive a job that is under the hood -
or
2) extend the InsertJSONStructure() and other similar functions to accept a new flag, eg #PB_JSON_ByteToBoolean which takes byte type values and converts them to JSON boolean true and false - without this flag bytes would be treated as normal of course
Rationale: APIs are usually strict things (with good reason). So if they specify a true/false value but get 1/0, they will probably fail.
The current work around is to insert each element from a structure one by one and using the JSON library's SetJSONBoolean() function, which involves a LOT more coding
Unless of course I have missed something and there is a way of doing this already with the existing commands?
Edit: renamed suggested new constant to include the word "JSON"
Suggestions:
1) new data type: boolean which has an integer range of 0 to 1 (ie false, true). Thus functions would know when to convert a value to boolean implicitely. Not sure how massive a job that is under the hood -
or
2) extend the InsertJSONStructure() and other similar functions to accept a new flag, eg #PB_JSON_ByteToBoolean which takes byte type values and converts them to JSON boolean true and false - without this flag bytes would be treated as normal of course
Rationale: APIs are usually strict things (with good reason). So if they specify a true/false value but get 1/0, they will probably fail.
The current work around is to insert each element from a structure one by one and using the JSON library's SetJSONBoolean() function, which involves a LOT more coding
Unless of course I have missed something and there is a way of doing this already with the existing commands?
Edit: renamed suggested new constant to include the word "JSON"