property_to_json Function
Syntax
Arguments
- propPointer
An object that contains the properties to convert to JSON.
- changesOnlyLogical
Returns
- jsonCharacter
Returns the dot variable as a JSON object.
Description
Takes a property, like a dot variable, and converts it to a JSON object.
Discussion
The property_to_json() function shares similarities with the json_generate() function. However, it uses a different mechanism and doesn't do nearly as much as json_generate.
dim prop as p prop.name_first = "John" prop.name_last = "Smith" prop.occupation = "Cobbler" ? property_to_json(prop) = {"name":"John","name_first":"John","name_last":"Smith","occupation":"Cobbler"}
Json_generate() is designed so that you can do a full "round trip" (i.e. json_generate(), followed by json_parse() of the string produced by json_generate()) without losing any information.
This is not the case with property_to_json().
For example:
dim p as p p.name = "Fred" p.city = "Boston" p.date = date() ?json_reformat(property_to_json(p)) = { "name": "Fred", "city": "Boston", "date": "2019-04-11" }
The above string is a valid JSON string, but notice that we have lost information about the original type of type of the "date" property.
See Also