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

JSON Parse Command for a JSON that starts with [

Postby AnandB » Fri Sep 06, 2019 5:18 pm

Hi,

I have a query regarding JSON PARSE statement; and corresponding COBOL declaration.

For the following JSON the corresponding COBOL declaration would be

JSON
client-data":{
"account-num":123456789012,
"balance":-125.53,
"billing-info":{
"name-first":"John",
"name-last":"Smith",
"addr-street":"12345 First Avenue",
"addr-city":"New York",
"addr-region":"New York",
"addr-code":"10203"
}
}

COBOL Declaration.
01 client-data.
03 account-num pic 999,999,999,999.
03 balance pic $$$9.99CR.
03 billing-info.
05 name-first pic X(20).
05 name-last pic X(20).
05 addr-street pic X(20).
05 addr-city pic X(20).
05 addr-region pic X(20).
05 addr-code pic X(10).

What would be the corresponding COBOL declaration if the JSON started with a "[" i,e. if the JSON looks like

client-data":[
"account-num":123456789012,
"balance":-125.53,
"billing-info":{
"name-first":"John",
"name-last":"Smith",
"addr-street":"12345 First Avenue",
"addr-city":"New York",
"addr-region":"New York",
"addr-code":"10203"
}
]

Thank you
Anand B.
Anand Biradar
AnandB
 
Posts: 6
Joined: Mon Dec 26, 2011 1:20 pm
Has thanked: 1 time
Been thanked: 0 time

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

 

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

Postby enrico-sorichetti » Fri Sep 06, 2019 10:14 pm

meditating on the cobol manual at the section "Handling JSON arrays"
will tell all You might want to know about the relative cobol declaration

https://www.ibm.com/support/knowledgece ... ml04d.html
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2884
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 153 times

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

Postby AnandB » Sat Sep 07, 2019 7:36 am

Thank you Enrico.

{"some-data":{"msg":[{"ver":5,"uid":10,"txt":"Hello"},{"ver":5,"uid":11,"txt":"World"},{"ver":5,"uid":12,"txt":"!"}]}}

Working-storage section.
1 some-data.
2 msg occurs 3.
4 ver usage comp-1.
4 uid pic 9999 usage display.
4 txt pic x(32).

The JSON I am working with has "[" before "msg"; something like
{"some-data":["msg":[{"ver":5,"uid":10,"txt":"Hello"},{"ver":5,"uid":11,"txt":"World"},{"ver":5,"uid":12,"txt":"!"}]]}.

some-data should be an array in this case, we cannot have occurs at 01 level in COBOL. The JSON is well within JSON standards.
Anand Biradar
AnandB
 
Posts: 6
Joined: Mon Dec 26, 2011 1:20 pm
Has thanked: 1 time
Been thanked: 0 time

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

Postby AnandB » Sat Sep 07, 2019 9:07 am

I used a dummy variable at level 01; followed by JSON data variables with occurs clause. In the Parse command I parsed JSON in the dummy variable with OMIT option. It looks to be working now. Thank you.
Anand Biradar
AnandB
 
Posts: 6
Joined: Mon Dec 26, 2011 1:20 pm
Has thanked: 1 time
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post