JSON Parse Command for a JSON that starts with [



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

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

Postby Pvernekar » Thu Mar 30, 2023 1:19 am

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:
Pvernekar
 
Posts: 3
Joined: Tue Mar 28, 2023 1:42 pm
Has thanked: 0 time
Been thanked: 0 time

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

Postby Robert Sample » Thu Mar 30, 2023 1:34 am

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.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Previous

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post