Correspondence between a JSON string and an EGL variable for zOS and IBM i

This topic describes the EGL record that corresponds to a JavaScript Object Notation (JSON) string. This topic describes the functions—serviceLib.convertFromJSON() and serviceLib.convertToJSON()—that are used by an EGL developer to convert JSON data to or from a variable either for zOS or IBM i systems. A failure in either function causes a RuntimeException.

JSON and EGL records on zOS:

To create a record part that matches the JSON string, ensure that each field name in the record part exactly matches (in character and case) each corresponding field name in the JSON string, as shown in the following example:

Record MyRecordPart
   EmpNo INT;
   LastName STRING;
end         
You can assign the following values for the variables defined in the record.
  EmpNo =10 
  LastName = "Smith"
The following JSON String will be generated for the given values .
  {“MyRecordPart” : { "EmpNo":10,"LastName":"Smith" }}
Note:
The generated JSON string would contain the name of the record at the beginning (“MyRecordPart”) and users should ensure that it should be a part of the input JSON string so that it can be processed by the JSON parser function.

Errors found while parsing or generating the JSON string will be issued by COBOL’s JSON PARSE and JSON GENERATE statements.

JSON and EGL records on IBM i:

To create a record part that matches the JSON string, ensure that each field name in the record part exactly matches (in character and case) each corresponding field name in the JSON string, as shown in the following example:

Record MyRecordPart
    EmNo INT;
    LastName STRING;
end         
You can assign the following values for the variables defined in the record.
  EmpNo =10 
  LastName = "Smith"
The following JSON String will be generated for the given values .
  { "EmpNo":10,"LastName":"Smith" }
Refer to the Special considerations for JSON support on IBM i for additional information on key considerations while using JSON parse and generate functions for IBM i.