ENTMF 

Appendix A - JSON PARSE Example

The following example demonstrates how you can parse a JSON text string into a COBOL group item.

Consider the following JSON text string:

{"msg":{"SND":9,"pid":1289,"txt":"Hello World!"}}

If you pass the string into the following COBOL program, you can see how it can be parsed, at which point you can query and manipulate the results:

       Identification division.
       Program-id. jparse1.
       Data division.
       Working-storage section.
       01 msg.
         03 snd usage comp-1.
         03 pid pic 9999 usage display.
         03 txt pic x(12).
       Linkage section.
       01 json-str pic x(53).
       Procedure division using json-str.
       display "Parsing....".
       JSON PARSE json-str into msg with DETAIL
       END-JSON.
       if snd equal to 9 then
          display "PID is " pid
          display "Message text is '" txt "'"
       end-if.
       goback.
       End program jparse1.

As a result of executing the JSON PARSE statement, the group msg is populated with the three values from the JSON text name/value pairs. At this point, you can manipulate the text in any way that you wish.