JSON and XML
| JSON PARSE | |
| JSON GENERATE | |
| XML PARSE |
JSON PARSE
COBOL 2014 added JSON. JSON PARSE reads a JSON document into a data item whose structure mirrors the document, mapping objects to groups and arrays to OCCURS:
JSON PARSE WS-JSON-DOC INTO WS-RESPONSE
ON EXCEPTION DISPLAY "Bad JSON"
NOT ON EXCEPTION DISPLAY "OK: " WS-RESPONSE-STATUS.
JSON GENERATE
JSON GENERATE writes a data item out as a JSON document. It is the other half of a REST client: parse the response in, generate the request out:
JSON GENERATE WS-OUT-DOC FROM WS-REQUEST
ON EXCEPTION DISPLAY "Generate failed".
XML PARSE
XML PARSE walks an XML document and calls a handler paragraph at each start-of-element, character, and end-of-event. It is lower level than JSON PARSE, and still the way to read legacy XML feeds.
Next: Calling C functions
Article author: Arthur Isaev