By default, the program currently runs the following JSON PARSE statement:
JSON PARSE JSON-TEXT-STRING INTO COBOL-STRUCTURE
After the JSON file has been parsed, the following output is displayed.
The Variables view shows the COBOL-STRUCTURE group being populated from the contents of the JSON file.
The program now runs the following JSON PARSE statement:
JSON PARSE JSON-TEXT-STRING INTO basic-person-info
WITH DETAIL
NOT ON EXCEPTION
PERFORM D150-DISPLAY-DATA2
GO TO J999-EXIT
END-JSON
Secondly, the display outputs from the EXCEPTION show us the error codes. The '106' is a fatal conversion error and the 3 is the reason. The error was caused by the fact that the JSON string contains the top-level field called 'COBOL-structure', which does not match the field name 'basic-person-info'.
The program now runs the following JSON PARSE statement:
JSON PARSE JSON-TEXT-STRING INTO basic-person-info
WITH DETAIL
NAME OF basic-person-info IS 'COBOL-STRUCTURE'
_reference of basic-person-info IS 'reference'
SUPPRESS lastName of basic-person-info
ON EXCEPTION
PERFORM D200-DISPLAY-JSON-STATUS
GO TO J999-EXIT
END-JSON
The array fields have been set to the maximum number, hence the PARSE informs us that there were less occurrences in the JSON string than the array is set to hold. There is also a list of the fields that were not parsed, as they were not present in the COBOL data structure. Lastly, the display statements confirm the contents of the fields, and the lastName field was correctly suppressed.
This concludes the tutorial.