#XPRIM_Json: Create Json with two arrays

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
René Houba
Posts: 220
Joined: Thu Nov 26, 2015 7:03 am

#XPRIM_Json: Create Json with two arrays

Post by René Houba »

Because there is no online #XPRIM_Json documentation available yet, I like to introduce some examples here. I hope that based on my examples, that others will follow and share their examples here as well.

This example creates a Json file with two arrays.

* Example with two Array's
Define_Com Class(#XPRIM_Json) Name(#json)
Define_Com Class(#XPRIM_JsonObject) Name(#jsonObj) Reference(*DYNAMIC)
Define_Com Class(#XPRIM_JsonObject) Name(#jsonNameObject) Reference(*DYNAMIC)

Define_Com Class(#XPRIM_JsonArray) Name(#jsonNamesArray) Reference(*DYNAMIC)
Define_Com Class(#XPRIM_JsonArray) Name(#jsonEmailArray) Reference(*DYNAMIC)

* Create root for JSON document
#jsonObj <= #json.CreateRootObject

* Create array for names
#jsonNamesArray <= #jsonObj.InsertArray( 'names' )

* Add name object, first name
#jsonNameObject <= #jsonNamesArray.InsertObject
* Add 1st level data in json name object
#jsonNameObject.InsertString Key("givenname") String('Peter')
#jsonNameObject.InsertString Key("lastname") String("Smith")
#jsonNameObject.InsertNumber Key('age') Number(58)

* Add email array into name object
#jsonEmailArray <= #jsonNameObject.InsertArray( 'email' )
#jsonEmailArray.InsertString String('[email protected]')
#jsonEmailArray.InsertString String('[email protected]')

* Add name object, second name
#jsonNameObject <= #jsonNamesArray.InsertObject
* Add 1st level data in json name object
#jsonNameObject.InsertString Key("givenname") String('Susan')
#jsonNameObject.InsertString Key("lastname") String("Walker")
#jsonNameObject.InsertNumber Key('age') Number(25)

* Add email array into name object
#jsonEmailArray <= #jsonNameObject.InsertArray( 'email' )
#jsonEmailArray.InsertString String('[email protected]')
#jsonEmailArray.InsertString String('[email protected]')

#jsonObj.SerializeToFile Path('C:\TEMP\JsonExampleWithTwoArrays.json')


Result:
Create Json with two arrays.PNG
Create Json with two arrays.PNG (13.15 KiB) Viewed 42540 times
Post Reply