Closed worksofliam closed 5 years ago
Both for newArray() and newObject() the "parent" parameter is depreciated - and will disappear in the new version of noxDB. You are using a notation used primary for backward compatibility but with the new feature locateOrCreate() so the behaviour is a little unpredictable ...
The code should look like the following which also is more flexible. You can move the the array into the object before or after the array contents. You can create the object before or after creating the array:
ctl-opt main(main) dftactgrp(*no);
ctl-opt bndDir('NOXDB');
/include ./headers/jsonparser.rpgle
Dcl-Proc main;
Dcl-S lArray Pointer;
Dcl-S lObject Pointer;
Dcl-S Result Char(52);
lObject = json_NewObject();
lArray = json_NewArray();
json_ArrayPush(lArray:'AAA');
json_ArrayPush(lArray:'BBB');
json_ArrayPush(lArray:'CCC');
json_moveObjectInto (lObject : 'args' : lArray);
Result = json_AsJsonText(lArray);
Dsply Result;
Result = json_AsJsonText(lObject);
Dsply Result;
Result = json_AsJsonText(json_Locate(lObject:'args'));
Dsply Result;
End-Proc;
Wow, thank you @NielsLiisberg - in fact, the parameters are documented as deprecated in the docs.. I just didn't read them. 🙄
Thanks!!
(This is happening on the master branch)
Below is an example script which creates an array, which is part of a object. I can explicitly reference the array in
JSON_asJsonText
which prints just fine, but if I reference the object it is part of, it does not print correctly.When
jsonStreamPrintNode
is called with the array node from the object, it thinks it is aPOINTER_VALUE
, which explains why it is coming back as a blank string - but does not explain why it works when we reference the array pointer defined in the program.