webspeed incoming json to temp-table

barutcuzade

New Member
I have an incoming json object formatted as such

{
"SFItemRequest": [
{
"customerNumber": "RIVE09",
"itemNumbers": [
"52900B150",
"94080B50",
"121200937"
]
}
]
}

what should be the corresponding temp-table structure to consume this input with hndSFItemRequest:READ-JSON("HANDLE", WEB-CONTEXT, "EMPTY").
 

Stefan

Well-Known Member
I find that it generally helps to first model a dataset that will produce the json that you are going to be consuming:

Code:
def var lcjson as longchar.

define temp-table tt serialize-name 'SFItemRequest'
   field cust  as char serialize-name 'customerNumber'
   field items as char serialize-name 'itemNumbers' extent 3
   .
define dataset ds for tt.

create tt. 
assign
    tt.cust = 'RIVE09'
    tt.items[1] = '52900B150'
    tt.items[2] = '94080B50'
    tt.items[3] = '121200937'
    .

dataset ds:write-json( 'longchar', lcjson, true, ?, ?, true ).
message string( lcjson ).

With the json output being identical, you can now process the response:

Code:
define temp-table tt serialize-name 'SFItemRequest'
   field cust  as char serialize-name 'customerNumber'
   field items as char serialize-name 'itemNumbers' extent 3
   .
define dataset ds for tt.

dataset ds:read-json( 'file', 'request.json' ).

for each tt:
   display tt.
end.
You can see the export and import working on ABL Dojo.
 

barutcuzade

New Member
thanks for the reply

what if I don't know how many items will be coming in?

just define a big enough extent to be safe?
 
Top