JSON: Difference between revisions

79 bytes added ,  13 August 2019
m
change "Command"
m (Corrections)
m (change "Command")
Line 73: Line 73:
This functionality is offered via the [https://docs.dataaccess.com/dataflexhelp/mergedProjects/VDFClassRef/cJsonObject.htm cJsonObject]
This functionality is offered via the [https://docs.dataaccess.com/dataflexhelp/mergedProjects/VDFClassRef/cJsonObject.htm 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.
One of the great features in that class is that you can move all your data from JSON into a struct with just one function or procedure call, and vice versa. In order to transfer your data from JSON to a struct you would use the [https://docs.dataaccess.com/dataflexhelp/mergedProjects/VDFClassRef/cJsonObject-Function-JsonToDataType.htm JsonToDataType] function and if you have to convert data from a struct to JSON then you can use the [https://docs.dataaccess.com/dataflexhelp/mergedProjects/VDFClassRef/cJsonObject-Procedure-DataTypeToJson.htm DataTypeToJson] procedure.
In order to transfer your data from JSON to a struct you would use the [https://docs.dataaccess.com/dataflexhelp/mergedProjects/VDFClassRef/cJsonObject-Function-JsonToDataType.htm JsonToDataType] function and if you have to convert data from a struct to JSON then you can use [https://docs.dataaccess.com/dataflexhelp/mergedProjects/VDFClassRef/cJsonObject-Procedure-DataTypeToJson.htm 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 [https://docs.dataaccess.com/dataflexhelp/mergedProjects/VDFClassRef/cJsonObject-Property-pbRequireAllMembers.htm pbRequireAllMembers] property of the DataFlex Json object to false.
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, so it has simply been omitted from the JSON. In that case the runtime will trigger a runtime error. You can disable that by setting the [https://docs.dataaccess.com/dataflexhelp/mergedProjects/VDFClassRef/cJsonObject-Property-pbRequireAllMembers.htm pbRequireAllMembers] property of the DataFlex Json object to false.


If you need to deal with JSON which uses DataFlex reserved words in its member names (or other invalid values, such as those containing spaces in the example above: e.g "first name") then, since DataFlex 19.1, you can now use a valid name in your struct and assign a different name for the conversion via meta-data tags. This is sometimes referred to as the [https://docs.dataaccess.com/dataflexhelp/mergedProjects/Tools/Name_Meta-Data_Tag.htm altName member]
If you need to deal with JSON which uses DataFlex reserved words in its member names (or other invalid values, such as those containing spaces in the example above: e.g "first name") then, since DataFlex 19.1, you can now use a valid name in your struct and assign a different name for the conversion via meta-data tags. This is sometimes referred to as the [https://docs.dataaccess.com/dataflexhelp/mergedProjects/Tools/Name_Meta-Data_Tag.htm altName member]