Create JSON from struct

From DataFlex Wiki
Revision as of 15:36, 11 September 2018 by Wil (talk | contribs) (Created page with "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. Ha...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

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
Get 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

External Links

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

https://support.dataaccess.com/Forums/showthread.php?63071-YAFR-Create-RDS-report-based-on-Struct-definition(s)&p=336276#post336276