Integrator JSON Wizard-List with subordinate fragment

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
markvillaplg
Posts: 3
Joined: Wed Aug 05, 2020 2:20 am

Integrator JSON Wizard-List with subordinate fragment

Post by markvillaplg »

As you know, we cannot load "lists within lists" in a LANSA working list. Below, I think this can be considered "standard JSON" and not violating any best practices. It is a list of payors. You might have 2 recipients...the problem is that "credentials" is a fragment (object) within this list and has a group of fields (properties) that cannot be loaded into (or written from) a list. The JSON Wizard ignores this part of the JSON structure. If anyone has any ideas on how to "solve the business problem" of writing this JSON from LANSA integrator HTTPOutboundJSONBindService - can you reply ? Also, if you know of any articles or standards the suggests that JSON API builders stay away from this technique (JSON objects within lists)...please share. In the LANSA world we might design multiple fragments (Objects of Properties) instead of "within a list", a dumbed-down version of the below. I think many service providers will be using the methods below:
{
"shipment": {
"payor": [
{
"type": "recipient",
"id": "id1",
"credentials": {
"accountNumber": "123456789",
"accountCountryCode": "US",
"accountPostalCode": "12341"
}
},
{
"type": "recipient",
"id": "id2",
"credentials": {
"accountNumber": "123456789",
"accountCountryCode": "US",
"accountPostalCode": "12341"
}
}
]
}
}
JamesDuignan
Posts: 85
Joined: Thu Nov 26, 2015 1:43 pm

Re: Integrator JSON Wizard-List with subordinate fragment

Post by JamesDuignan »

Hi Mark,

Based off of your sample JSON structure this is not hard to solve, I have had to build json messages similar to this before.

In integrator even if it is JSON array, each object in the array can be accessed or written to as an individual GET/SET fragment using a loop, it does not have to be done using GET/SET LIST

The important thing is, in the server types have the Payor object defined as a list, but in the project specify it as a fragment
Server Types.png
Server Types.png (10.35 KiB) Viewed 62659 times
Project.png
Project.png (17.53 KiB) Viewed 62659 times

Then you can do something like this for writting to the JSON

Code: Select all

Selectlist Named(#Payor_list) /* Get all the Payors */
* Set the Payor
Change Field(#JSMXCMD) To('SET FRAGMENT(PAYOR) SERVICE_EXCHANGE(*FIELD)')
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMXSTS #JSMXMSG)
Execute Subroutine(CHECK) With_Parms(#JSMXSTS #JSMXMSG)

#lPayorId := #PayorID

Loc_Entry In_List(#Cred_List) Where(#lPayorid = #PayorID)
* Set the credentials for that payor
Change Field(#JSMXCMD) To('SET FRAGMENT(CREDENTIALS) SERVICE_EXCHANGE(*FIELD)')
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMXSTS #JSMXMSG)
Execute Subroutine(CHECK) With_Parms(#JSMXSTS #JSMXMSG)
Or something like this for reading the JSON

Code: Select all

BEGIN_LOOP /* Loop over all the payors in the JSON Array*/

* Get fragment - PAYOR
CHANGE     FIELD(#JSMXCMD) TO('GET FRAGMENT(PAYOR) SERVICE_EXCHANGE(*FIELD)')
USE        BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMXSTS #JSMXMSG)

LEAVE      IF('#JSMXSTS *EQ NOFRAGMENT') /* leave if there are no more fragments to read */

EXECUTE    SUBROUTINE(CHECK) WITH_PARMS(#JSMXSTS #JSMXMSG)
Add_Entry To_List(#Payor_List)

* Get Credentials for that payor
CHANGE     FIELD(#JSMXCMD) TO('GET FRAGMENT(CREDENTIALS) SERVICE_EXCHANGE(*FIELD)')
USE        BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMXSTS #JSMXMSG)
EXECUTE    SUBROUTINE(CHECK) WITH_PARMS(#JSMXSTS #JSMXMSG)
Add_Entry To_List(#Cred_List)

END_LOOP /* PAYOR */
Cheers,
James
markvillaplg
Posts: 3
Joined: Wed Aug 05, 2020 2:20 am

Re: Integrator JSON Wizard-List with subordinate fragment

Post by markvillaplg »

James, your technique works fine...Thank You for the response.
Post Reply