Create JSON from struct

From DataFlex Wiki
Jump to navigationJump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Sometimes you have data as a DataFlex struct, but need it in JSON format.

The code below gives an example on how-to change your data format so that it is available as JSON.

 
 Handle hoJson
 UChar[] ucaJson
 Integer iChn
 tYourDataType tYourStructVar
 
 Get Create (RefClass(cJsonObject)) to hoJson
 Send DataTypeToJson of hoJson tYourStructVar
 Get StringifyUTF8 of hoJson to ucaJson
 Get Seq_New_Channel to iChn
 Direct_Output channel iChn {filename}
 Write channel iChn ucaJson
 Close_Output
 Send Seq_Release_Channel iChn
 Send Destroy of hoJson

External Links

The above was written by Mike Peat and has been taken from the following forum post: