/** * \brief JSON Parser example * * Parses a JSON string and generates from the JSON object a new * JSON string. * *

* * The parser is quite tolerant. It accepts = instead of : . Quotes can be * either single or double quotes. ; is also accepted instead of , . * *

* * * { "Product number" : 186189 , * "Product description": "After Eight 200gr" , * "In stock" : 52455 ; ' + * "Distribution lock" : False , * "Cost" = 1.235 , * "Supplier" = 358 , * "Category" = { "Id" : 15 , "Description": "Sweets"}, * "Product line" : [ * {"Sweets" = "120.1.1." } , * {"Chocolate" = "120.1.2" } ] , * "Assigned stocks" = [ ] , * "Assigned display" = {} * } * * * \author Mihael Schmidt * \date 13.03.2009 */ H dftactgrp(*no) actgrp(*caller) H bnddir('QC2LE') *------------------------------------------------------------------------ * Prototypes *------------------------------------------------------------------------ /include 'json/json_h.rpgle' *------------------------------------------------------------------------ * Variables *------------------------------------------------------------------------ D json S * D string S 65535A D json_string S 65535A /free string = '{ "Product number" : 186189 , ' + '"Product description": "After Eight 200gr" , ' + '"In stock" : 52455 ; ' + '"Distribution lock" : False , ' + '"Cost" = 1.235 , ' + '"Supplier" = 358 , ' + '"Category" = { "Id" : 15 , "Description": "Sweets"}, ' + '"Product line" : [ ' + '{"Sweets" = "120.1.1." } , ' + '{"Chocolate" = "120.1.2" } ' + '] , ' + '"Assigned stocks" = [ ] ,' + '"Assigned display" = {} ' + '} ' + x'00'; json = json_parse(%addr(string)); json_string = %str(json_toString(json)); dsply %subst(json_string : 1 : 50); dsply %subst(json_string : 51 : 50); dsply %subst(json_string : 101 : 50); dsply %subst(json_string : 151 : 50); dsply %subst(json_string : 201 : 50); dsply %subst(json_string : 251 : 50); dsply %subst(json_string : 301 : 50); dsply %subst(json_string : 351 : 50); json_dispose(json); *inlr = *on; return; /end-free