Page 1 of 1

Integrator JSON Wizard-List with subordinate fragment

Posted: Fri Apr 25, 2025 11:28 pm
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"
}
}
]
}
}

Re: Integrator JSON Wizard-List with subordinate fragment

Posted: Wed Apr 30, 2025 10:54 am
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 62655 times
Project.png
Project.png (17.53 KiB) Viewed 62655 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

Re: Integrator JSON Wizard-List with subordinate fragment

Posted: Sat Jun 21, 2025 6:49 am
by markvillaplg
James, your technique works fine...Thank You for the response.