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"
}
}
]
}
}
Integrator JSON Wizard-List with subordinate fragment
-
markvillaplg
- Posts: 3
- Joined: Wed Aug 05, 2020 2:20 am
-
JamesDuignan
- Posts: 85
- Joined: Thu Nov 26, 2015 1:43 pm
Re: Integrator JSON Wizard-List with subordinate fragment
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
Then you can do something like this for writting to the JSON
Or something like this for reading the JSON
Cheers,
James
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
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)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 */
James
-
markvillaplg
- Posts: 3
- Joined: Wed Aug 05, 2020 2:20 am
Re: Integrator JSON Wizard-List with subordinate fragment
James, your technique works fine...Thank You for the response.