Hi Guys,
This is the code I used:
Driver program:
IDENTIFICATION DIVISION.
PROGRAM-ID. occ1run.
* cob2 occ1run.cbl occ1.cbl -o occ1run.exe
DATA DIVISION.
WORKING-STORAGE SECTION.
01 j pic X(128) value
'{"some-data":{"msg":[{"ver":5,"uid":10,"txt":"Hello"},{"ver"
- ':5,"uid":11,"txt":"World"},{"ver":5,"uid":12,"txt":"!"}]}}'
.
PROCEDURE DIVISION.
DISPLAY "occ1run J = " J.
CALL "OCC1" USING J.
GOBACK.
Program copied from IBM docs, I added the clauses "detail encoding from codepage":
Identification division.
Program-id. occ1.
Data division.
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).
Linkage section.
1 json-text pic x(128).
Procedure division using json-text.
Json parse json-text into some-data
*> added by me:
detail encoding from codepage
end-json.
If ver(1) equal to 5 then
Display "Message ID is " uid(1)
Display "Message text is '" txt(1) "'".
If ver(2) equal to 5 then
Display "Message ID is " uid(2)
Display "Message text is '" txt(2) "'".
If ver(3) equal to 5 then
Display "Message ID is " uid(3)
Display "Message text is '" txt(3) "'".
Goback.
End program occ1.
How I compile from bash (I added the compiler options as IBM's support requested and sent to them):
cob2 -qLIST,MAP,NOOFFSET,NOSUPPRESS \
occ1run.cbl occ1.cbl -o occ1run.exe
Run:
OLS0009:/ol/ols0009/fifo: >occ1run.exe
occ1run J = {"some-data":{"msg":[{"ver":5,"uid":10,"txt":"Hello"},{"ver":5,"uid":11,"txt":"World"},{"ver":5,"uid":12,"txt":"!"}]}}
IGZ0339W During execution of the JSON PARSE statement on line 13 of program OCC1, the value of JSON name/value pair
with name "msg" at offset 20 was found to be incompatible with the matching data item.
Looks like is not a charset problem since it found "msg" property name.
Regards!
------------------------------
Sergio Samayoa
------------------------------
Original Message:
Sent: Fri March 20, 2026 02:55 AM
From: Loic Vital-Durand
Subject: JSON PARSE wont parse object arrays :(
Hello Sergio,
As Roy mentioned it would be good to share some code to get help ;)
Also adding some tips to what Jeffery explained :
- find the ccsid and use encoding in the parse
- 77 W-CCSID PIC 9(5).
- EVALUATE function
HEX-OF(theJsonToBeParsed(1:1))
WHEN '43' (swedish)
MOVE 278 to W-CCSID
DISPLAY 'message is EBCDIC.' W-CCSID
WHEN '7B' (utf-8)
MOVE 1208 to W-CCSID
DISPLAY 'message is UTF8.' W-CCSID
WHEN OTHER
DISPLAY 'message can not be parsed unknown ccsid '
' first chars are -->' function HEX-OF(theJsonToBeParsed(1:50))
'<--'
END-EVALUATE
- Parse the message fist without "WITH DETAIL" and if it goes wrong (ON EXCEPTION) parse it again WITH DETAIL. Doing so you will avoid having a huge sysout if it goes fine but will get all the parsing details if it goes wrong
JSON PARSE theJsonToBeParsed
INTO theWorkingStoragePlace
ENCODING W-CCSID
NAME REQUEST IS OMITTED
REQappId IS 'appId'
....
CONVERTING REQshowIssues FROM BOOLEAN
USING REQshowIssues-flag
ALSO REQFL-AM FROM BOOLEAN
USING REQFL-AM-flag
.....
ON EXCEPTION
ADD 1 TO PARSE-KO
DISPLAY 'Parse msg went wrong'
JSON PARSE theJsonToBeParsed
INTO theWorkingStoragePlace
WITH DETAIL
ENCODING W-CCSID
NAME REQUEST IS OMITTED
REQappId IS 'appId'
....
CONVERTING REQshowIssues FROM BOOLEAN
USING REQshowIssues-flag
ALSO REQFL-AM FROM BOOLEAN
USING REQFL-AM-flag
.....
ON EXCEPTION
ADD 1 TO PARSE-KO
DISPLAY 'Parse msg went wrong'
PERFORM errorAndStop
NOT ON EXCEPTION
ADD 1 TO PARSE-OK
DISPLAY 'Parse msg went ok'
END-JSON
NOT ON EXCEPTION
ADD 1 TO PARSE-OK
DISPLAY 'Parse msg went ok'
END-JSON
Hope it helps
/Loic
------------------------------
Loic Vital-Durand
Original Message:
Sent: Wed March 18, 2026 08:05 PM
From: Sergio Samayoa
Subject: JSON PARSE wont parse object arrays :(
I was writing a COBOL program which receive its operational parameters in JSON format but happens than when I started to test I started to get this message:
IGZ0339W During execution of the JSON PARSE statement on line 23 of program XXXX, the value of JSON name/value pair
with name "XXXX" at offset 999 was found to be incompatible with the matching data item.
So I tried the example programs from here: https://www.ibm.com/docs/en/cobol-zos/6.4.0?topic=input-handling-json-arrays but they gave me the same result.
Have you used JSON PARSE with object arrays successfully?
Any help appreciated!
------------------------------
Sergio Samayoa
------------------------------