Is it possible to use JSON PARSE with dynamic name fields?

Hi 

I'd like to use JSON PARSE instead of UNSTRING to parse the JSON structure shown below. My problem is that the  content and exact spelling  of  the  middle lines starting with "161 Waist" and "162 Seat" are not known at compile time, only at run time. Is it possible to define a COBOL data structure that can be used with JSON parse to handle this kind of thing?

Thanks

 

{ "jsonrpc": "2.0", "message": "MeasureResults", "params": { "ID": "0001", "161 Waist": "25.000", "162 Seat": "37.000", "status": "not OK" } }

 

  • I do not find that this is currently supported.

    According to the JSON rules of pattern matching which can be found in the docs here, the JSON data can contain data items that are not defined within the COBOL group item, but that these will be ignored. There is no option to use a field name that is generated dynamically. 

    This is the example that is provided:

    Conversely, additional items in the JSON text are tolerated, but generate non-zero JSON-STATUS codes and run-time messages. The following examples are compatible, and a JSON PARSE operation would completely populate Grp-1, but leave the JSON name/value pair "X-X": "Y" untouched. The statement would terminate without an exception code, but the special register JSON-STATUS is set to a reason code of 2:

    01. Grp-1.
        03 a.
           05 grk pic x(15).
           05 8_ pic 9.
           05 A-a pic x(5).  

    The JSON text:

    {"grp-1": {"A": {"GrK": "ERK*VML", "8_": 8, "X-X": "Y", "a-A": "VOID"}}}

     

  • Hi Chris

    The fact that the data names for the  JSON  "name" need to be determined at compile time seems like a very unfortunate limitation on the MicroFocus JSON PARSE verb.

    There are simple implementations of JSON PARSE in other languages  like C  that  work at run time. These  return name value pairs  with data types and offsets into the JSON input string. I'm thinking about JSMN for example. These go a long way in producing usable information and seem like a much more flexible approach. 

    Thanks anyway 

    Elliot

  • The JSON PARSE syntax & behaviour is designed to be compatible with the mainframe version of the same syntax.

    So, although I do agree it could be more flexible, it is constrained by the requirement to be compatible with the mainframe implementation.