Question
Rochdi Badis · May 3

Resultset to JSON

Hi Guys,

How do I convert a Query resultset to JSON file ?

 

Thanks

Product version: Ensemble 2014.1
0
0 102
Discussion (3)1
Log in or sign up to continue

You can build a %Library.DynamicObject or a %Library.DynamicArray (both extend the %Library.DynamicAbstractObject class) from the ResultSet and use the %ToJSON method.
To build the object it will be necessary to loop the ResultSet writing line by line.

In Ensemble 2014, which the author indicated in his question, there are no classes %Library.DynamicObject and %Library.DynamicArray

See %ZEN.Auxiliary.jsonSQLProvider:%WriteJSONStreamFromSQL()

 
Simple example

The contents of the file test.json (UTF8):

{
"children":[
{"ID":1,"Date":"04.05.2022","bool":0,"int":30,"str":"Hello Caché"}
,{"ID":2,"Date":"31.12.1840","bool":1,"int":303,"str":"ăîşţâ"}
,{"ID":3,"Date":"","bool":"","int":"","str":""}
]
}