RPG Next Gen
Wiki RSS Feed Weblog
Business picture

JSON Utilities

JSON Generator

The main module can be used to create JSON strings. First a JSON object is created. Then the various put and get procedures can be used to fill or query the object for its content. With the toString procedure the JSON string is generated from the object.

The generator supports arrays and objects in unlimited depths. The only limit is the memory the job is allowed to allocate.


// create json object jsonObj = json_create(); // fill json object json_putBoolean(jsonObj : 'Error' : *on); json_putInt(jsonObj : 'ErrorId' : 358); json_putString(jsonObj : 'ErrorDesc' : 'My custom error message.'); json_putString(jsonObj : 'ErrorTime' : %char(%time : *HMS:)); // generate json string jsonString = %str(json_toString(jsonObj)); // dispose json objet => free allocated memory json_dispose(jsonObj);