Create aJSON file
Hi Guys,
How do I create a JSON with the below structure pls:
{
"field 1": "123",
"field 2": "1.1.1",
"field 3": "4.428",
"Lines": [
[ 0.00523, 0.00952, 0.01626 ],
[ -0.00303, -0.00286, 0.00387 ],
[ 0.00110, 0.00814, 0.00800 ],
[ -0.00991, 0.00952, 0.00800 ]
]
}
thanks
Comments
As you operate on 2014.* just write it down as any other string.
after 2017.1 you may (but are not forced to) use %DynamicObjects and %%DynamicArrays.
but the result looks the same
The %Library.DynamicAbstractObject, %Library.DynamicArray and %Library.DynamicObject classes with the %ToJSON and %FromJSON methods first appeared in Caché 2016.2. I believe that 2016.2 also included JSON constructor syntax in ObjectScript. I.e., you could write SET jsonvar={"number":1.2, "string":"abcd",null,true} as an executable ObjectScript statement. Any JSON constant array or object is legal. I am not sure when JSON constructors involving ObjectScript expressions was allowed. E.g. SET jsonvar={"number":(1+.2+variable1), "string":("abcd"_variable2),null,false}. Newer versions of Caché have more JSON support and IRIS has even more support, including the %JSON.Adapter class. Inheriting the %JSON.Adapter class makes it possible to use the %JSONImport/%JSONExport methods which can read/writeJSON representation into/from ordinary class definitions.