Difference between revisions of "JSON"
(Adding a page for JSON)
Revision as of 10:55, 13 August 2019
It is a format that is often used in RESTful webservices and as such it is important to be able to use it from within DataFlex.
Before DataFlex 19.0 you had to resort to external libraries in order to use JSON, see for example JSON Parsing ... the beginnings of an alternative approach
As of DataFlex 19.0 we have native support for JSON objects and can access and directly work with these data structures. This functionality is offered via the cJsonObject
One of the great features in that class is that you can move all your data from JSON into a struct with just one command and vice versa. In order to transfer your data from JSON to a struct you would use the JsonToDataType function and if you have to convert data from a struct to JSON then you can use DataTypeToJson.
When migrating data from JSON to a struct sometimes a member might be missing from the JSON data. For example because the element you are looking for is empty. In that case the runtime will trigger a runtime error. You can disable that by setting the pbRequireAllMembers property of the DataFlex Json object to false.
If you have a struct that uses reserved words then since DataFlex 19.1 you can now use a non reserved name and assign a different name for the conversion via meta-data tags. This is sometimes referred to as the altName member