So I have a JSON string I'd like to load into a JSONpackage object for further processing. Problem is (apparently) it is an array which I guess the JSONPackage object cannot handle. I get this error: Failed to load the JSON data because its root node is not an object
So, how do I process the file? I assume some kind of loop through the JSON?
Code I tried:
ls_mess = ljs_pack1.loadstring(ls_pack_json) //Gives the "Failed to load the JSON data..." if the JSON is an array.
ls_jpk_json = ljs_pack1.GetValue("_patientCaseLimited") //If ls_pack_json is not an array this works since it is successfully loaded.
Link to JSON file:
https://www.dropbox.com/s/u54ic1jb1pdgl4o/sample.json?dl=0
Thank you
UPDATE with Solution
Here is what I ended up with to solve my particular problem.
The data is an array which has a second array (called '_patientCaseLimited') and it is this piece I need.
//ljs_pack is a JSONPackage object
//ljs_parser is a JSONParser object
ls_pack_json = ljs_pack.GetValue("Data") // gets the JSON data
ls_message = ljs_parser.loadstring(ls_pack_json)
ll_arrayitem = ljs_parser.getrootitem() // start at the root
ll_childcount = ljs_parser.getchildcount(ll_arrayitem) // how many child elements?
FOR ll_i = 1 to ll_childcount
ll_objectitem = ljs_parser.getchilditem(ll_arrayitem, ll_i) //next child array element
ls_casejson += ljs_parser.getitemarrayjsonstring(ll_objectitem, "_patientCaseLimited") //append arrays
NEXT
ls_jpk_json = lnv_string.of_globalreplace(ls_casejson, '][', ',') //PFC String Service
Now I can import the ls_jpk_json into a datawindow