Question
· May 17, 2022

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

Product version: Ensemble 2014.1
Discussion (2)2
Log in or sign up to continue

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.