Changing JSON component
Hi Guys,
I'm using the following to display JSON content in an areatextbox, but I would like to change a value in my JSON before displaying it in my areabox?
set txtId.value= jobj.SampleJsonData.Read(jobj.SampleJsonData.Size)
say for example my JSON string as below and would like to change Type value, I thought of converting the JSON to object
(d ##class(%ZEN.Auxiliary.jsonProvider).%ConvertJSONToObject(jobj.SampleJsonData.Read(jobj.SampleJsonData.Size),,.list) )
Set the value of Type : list.Type
then convert the Object back to JSON but I couldn't find a function or method that convert Object back to JSON?
{
"Number":"091820246OB",
"id":42961251,
"SensorId":"001D091N",
"Type":"CTR"
}
Thanks
Comments
Hi John,
In the same class %ZEN.Auxiliary.jsonProvider that you used for the JSON to Object version there is another method %ObjectToJSON which I believe is what you are looking for. This will write out the contents of object instance pObject to the current device using JSON notation.
Another slightly different option is to use the %DynamicAbstractObject class and methods %FromJSON which given a valid JSON string will parse it and return an object of datatype %DynamicAbstractObject and %ToJSON which will convert an instance of %DynamicAbstractObject into a JSON string.
Please note that the version of Documentation I consulted for these was Cache and Ensemble Version 2018.1.9
Thanks Hannah
Just a note for reference in future. The DynamicAbstractObject functionality was fully implemented in Caché 2016.2 and up (there was a version in 2016.1, but the syntax is different). If you are on a higher version that this, using it is generally preferable to the ZENProxyObject version