Start of change

Examples of matched and mismatched data definitions and JSON text

The following data definitions and JSON text are considered an exact match.

Data definitions:
01 G.
  05 h.
    10 a pic x(10).
    10 3_ pic 9.
    10 C-c pic x(10).

JSON text:
{"g": {"H": {"A": "Eh?", "3_": 5, "c-C": "See"}}}
The JSON text subsequently generated from this structure would also be an exact match for the JSON text input to the JSON PARSE statement:
{"G": {"h": {"a": "Eh?", "3_": 5, "C-c": "See"}}}
Omission in the JSON text of names corresponding with elementary items or complete substructures is tolerated, but the level (“qualification”) must match. For example, the following data definitions and JSON text are compatible, but data-items “3_” and “etCetera” would not be modified by the corresponding JSON PARSE statement, and would result in a JSON-STATUS value of 1 at statement termination and a runtime message under control of the WITH DETAIL phrase:
01 G.
  05 h.
    10 a pic x(10).
    10 3_ pic 9.
    10 C-c pic x(10).
  05 etCetera.
    10 etCetera pic x(10).

{"g": {"H": {"A": "Eh?", "c-C": "See"}}}
Superfluous items in the JSON are tolerated, but result in nonzero JSON-STATUS codes, and runtime messages under control of the WITH DETAIL phrase. For example, the following data definitions and JSON text are compatible, and would result in completely populating group G, and terminating without an exception. However, because JSON name/value pair "B": "Bee" would not be used, special register JSON-STATUS would be set to a reason code of 2:
01 G.
  05 h.
    10 a pic x(10).
    10 3_ pic 9.
    10 C-c pic x(10).

{"G": {"h": {"A": "Eh?", "B": "Bee", "3_": 5, "c-C": "See"}}}
The following data definitions and JSON text are fully compatible, despite the name order mismatch.
01 G.
  05 h.
    10 a pic x(10).
    10 3_ pic 9.
    10 C-c pic x(10).

{"g": {"H": {"3_": 5, "A": "Eh?", "c-C": "See"}}}
The following data definitions and JSON text are not compatible, because of the omitted name level (qualification by “H”), and, because no data items would be changed, would result in an exception condition:
01 G.
  05 h.
    10 a pic x(10).
    10 3_ pic 9.
    10 C-c pic x(10).

{"g": {"A": "Eh?", "3_": 5, "c-C": "See"}}
The following data definitions and JSON text are not compatible, because the JSON values are all incompatible with the corresponding data items, and would result in an exception condition:
01 G.
  02 h.
    10 a pic a(10).
    10 3_ pic 9.
    10 C-c pic 99.

{"g": {"H": {"A": 42, "3_": "x", "c-C": "abc"}}}
End of change