It turns out that you can build JSON structures without ever calling the JSONBuilder function block directly. Instead, create a pointer to JSON.JSONData and invoke the necessary methods on its dereference. The parent object has a parent index of -1 (and an index of 0). EVERY other item (including keys, values, empty arrays and sub-objects) created by the setX methods needs the index to increase by 1.
Then use the JSONByteArrayWriter FB to generate your JSON string
Last edit: corriibme 2024-05-23
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have been trying to set an array value to a JSON structure of this form:
{"key": [1,2,3,4]}
While I have been able to create the key and set its value to an empty array, I've not had any luck in putting any value in that array.
iValue2: ARRAY[0..3] OF INT:= [1,2,3,4];
The two lines of code above produce {"key6": []} . The second line essentially has no effect.
It turns out that you can build JSON structures without ever calling the JSONBuilder function block directly. Instead, create a pointer to JSON.JSONData and invoke the necessary methods on its dereference. The parent object has a parent index of -1 (and an index of 0). EVERY other item (including keys, values, empty arrays and sub-objects) created by the setX methods needs the index to increase by 1.
Then use the JSONByteArrayWriter FB to generate your JSON string
Last edit: corriibme 2024-05-23