Page 2 of 2

Re: JSON Parse Command for a JSON that starts with [

PostPosted: Thu Mar 30, 2023 1:19 am
by Pvernekar
Thanks Robert.
We use Enterprise COBOL 6.3 and the single response worked.
countryCode:FR
formStatusChangeReason:
id:XXX-XX-XXXX
signatureDate:2018-01-01
status:
type:AB

Was trying for array-->
01 inrec.
05 pic u(50)
VALUE '{"countryCode": "FR","formStatusChangeReason": "",'.
05 pic u(30)
value '"id-n": "XXX-XX-XXXX",'.
05 pic u(30)
value '"signatureDate": "2018-01-01",'.
05 pic u(30)
value '"status-c": " ","type-c": "AB"}'.
05 pic u(50)
VALUE '{"countryCode": "NJ","formStatusChangeReason": "",'.
05 pic u(30)
value '"id-n": "IXX-XX-XXXX",'.
05 pic u(30)
value '"signatureDate": "2022-01-01",'.
05 pic u(30)
value '"status-c": " ","type-c": "DA"}'.
05 pic u(736).

01 resp-rec.
02 RESP-ARRAY OCCURS 02 TIMES.
05 countryCode PIC X(02).
05 formStatusChangeReason PIC X(40).
05 id-n PIC X(12).
05 signatureDate PIC X(10).
05 status-c PIC X(01).
05 type-c PIC X(02).

JSON PARSE inrec INTO resp-rec WITH DETAIL
NAME resp-rec IS OMITTED.
display 'resp-rec written:'resp-rec.
display 'countryCode:' countryCode(1).
display 'countryCode:' countryCode(2).
display 'formStatusChangeReason:'formStatusChangeReason(1).
display 'formStatusChangeReason:'formStatusChangeReason(2).
display 'id:' id-n(1)
display 'id:' id-n(2).
display 'signatureDate:' signatureDate(1).
display 'signatureDate:' signatureDate(2).
display 'status:' status-c(1).
display 'status:' status-c(1).
display 'type:' type-c(1).
display 'type:' type-c(2).

during execution got below
IGZ0322I During execution of the JSON PARSE statement on line 394 of program JPARPGM, no data item matched JSON name "countryCode" at offset 1.
IGZ0322I During execution of the JSON PARSE statement on line 394 of program JPARPGM, no data item matched JSON name "formStatusChangeReason" at offset 21.
IGZ0322I During execution of the JSON PARSE statement on line 394 of program JPARPGM, no data item matched JSON name "id-n" at offset 200.
IGZ0322I During execution of the JSON PARSE statement on line 394 of program JPARPGM, no data item matched JSON name "signatureDate" at offset 320.
IGZ0322I During execution of the JSON PARSE statement on line 394 of program JPARPGM, no data item matched JSON name "status-c" at offset 440.
IGZ0322I During execution of the JSON PARSE statement on line 394 of program JPARPGM, no data item matched JSON name "type-c" at offset 456.

countryCode:
countryCode:
formStatusChangeReason:
formStatusChangeReason:
id:
id:
signatureDate:
signatureDate:
status:
status:
type:
type:

Re: JSON Parse Command for a JSON that starts with [

PostPosted: Thu Mar 30, 2023 1:34 am
by Robert Sample
The Language Reference manual explains your results:
The following data items that are specified by identifier-2 are ignored by
the JSON PARSE statement:
v Any subordinate unnamed elementary data items or elementary FILLER
data items
v Any slack bytes inserted for SYNCHRONIZED items
v Any data item subordinate to identifier-2 that is defined with the
REDEFINES clause or that is subordinate to such a redefining item
v Any data item subordinate to identifier-2 that is defined with the
RENAMES clause
v Any group data item all of whose subordinate data items are ignored
The last point is where you got tripped up -- RESP-ARRAY is a group data item so everything under it will be ignored.