I Found my thinking mistake. You made it that you can onlyh parse from and to a struct of the same instance name.
In my example I parse a writing struct and than parse it back into a reading struct of the same type. But as the writing and reading struct have different instance names this match all levels does not become true making the reading struct empty.
So parsing to and from 1 struct instance will work.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I am using this library. but i am facing some issue. i dont know if this is how the library is supposed to work!
I am parsing from a JSON string to a JSON struct and the JSON struct has an array in one of its variable. and the array index starts from 0. but then, in the 0 th index of the array i am not getting the expected value. rather the values start from 1st array index.
Is this the actual working of the library?
or am i missing some configuration?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I created a FB that read JSON file and convert it to the normal DUTs with this library.
May be usefull for somebody: https://github.com/Risele/CodesysJSONFile/
There are project at Win3 Virtual controller + exported code (normal .export and xml)
Also I made some notes about library limitations I found. Leaving here for others.
Naming
The names in JSON and in ST-based JSONVARs should match exactly. For JSON fields of
This should be fixed in the new version 1.0.18.0. I did some restructuring to fix some issues with arrays. Only thing I haven't done yet is multi-dimensional arrays.
👍
1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Bugs detected during testing with PROJSON 1.0.16.0:
A new bug has been discovered in the PROJSON library, an incorrect JSON is produced when the message to be composed is a structure array, and one of its attributes is another structure:
Example that does not work :
testLevel1:JSONVAR;house.rooms[1..N].window.Var1
Example that works :
testLevel1: JSONVAR;
house.rooms[1..N].Var1
Example that works :
house.room1.window.Var1
In our testing phase, we took into account previously identified bugs, in particular:
- The prohibition of having a single array in a JSON structure; it must be preceded by a JSON variable.
- The array index must start at 1.
Solution: We adopted the latter solution, defining each room flatly to avoid having a structure array whose attributes
include another structure:
house.room1.window.koeffCorrecteur
house.room2.window.koeffCorrecteur
...
house.room7.window.koeffCorrecteur
👍
1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello everyone, I found a bug in Version 1.0.18.0.
I have a structure:
TYPE ST_JSON_TEST :
STRUCT
testList : ARRAY[0..1] OF JSONVAR;
END_STRUCT
END_TYPE
It is declared as follows:
stJsonTest : ST_JSON_TEST;
stJsonTest.testList[0].CharString := 'used';
stJsonTest.testList[1] is null;
I called the method "STRUCT_TO_JSON" with the input parameter "IgnoreNull := true".
After that, the string I got is:
'{"stJsonTest":{"testList":["used"}]}'
You can see that the position of ']' is incorrect. Does anyone know how to fix this? Thank you for any advice!
Last edit: lucawu 2025-12-11
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you for your fixes. I tried version 1.0.21.0 of your library, and the Rootless feature for STRUCT_TO_JSON works great.
However, I found that it still doesn't correctly output the closing brackets when serializing an array of structures. Have you tested this kind of structure:
TYPE ST_PLANT :
STRUCT
NAME : JSONVAR;
QUANTITY : JSONVAR;
END_STRUCT
END_TYPE
TYPE ST_ANIMAL :
STRUCT
NAME : JSONVAR;
AGE : JSONVAR;
END_STRUCT
END_TYPE
TYPE ST_BIOTA :
STRUCT
PLANT : ARRAY[0..3] OF ST_PLANT;
ANIMAL : ARRAY[0..3] OF ST_ANIMAL;
END_STRUCT
END_TYPE
When using STRUCT_TO_JSON with my ST_BIOTA structure, regardless of whether my Rootless setting is TRUE or FALSE, the generated string is always missing the final ']' and the preceding '}'. I would be very grateful if you could clarify this issue for me.
Regardless, thank you again for your contribution, respect!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
UPD:
for top-level described array it also provides valid output, BUT only with ROOTLESS=FALSE option. It's not an error, I suppose, since nameless array could not exists in JSON.
more posts ...
I Found my thinking mistake. You made it that you can onlyh parse from and to a struct of the same instance name.
In my example I parse a writing struct and than parse it back into a reading struct of the same type. But as the writing and reading struct have different instance names this match all levels does not become true making the reading struct empty.
So parsing to and from 1 struct instance will work.
Correct. In an actual use case I think the compose and parse would happen on different machines.
Hi,
I am using this library. but i am facing some issue. i dont know if this is how the library is supposed to work!
I am parsing from a JSON string to a JSON struct and the JSON struct has an array in one of its variable. and the array index starts from 0. but then, in the 0 th index of the array i am not getting the expected value. rather the values start from 1st array index.
Is this the actual working of the library?
or am i missing some configuration?
This should be fixed in the new version 1.0.18.0. Previous to that version, only 1-based arrays were supported.
Hi,
I created a FB that read JSON file and convert it to the normal DUTs with this library.
May be usefull for somebody:
https://github.com/Risele/CodesysJSONFile/
There are project at Win3 Virtual controller + exported code (normal .export and xml)
Also I made some notes about library limitations I found. Leaving here for others.
Naming
The names in JSON and in ST-based JSONVARs should match exactly. For JSON fields of
ST-struct should be:
Arrays
The Array could not be topmost structure:
This is NOT valid.
The topmost array should be named:
The corresponding ST structure is
And the name of the array in the ST code should match the JSON exactly:
UTF8
Does not work with non-english UTF8 symbols (or I failed to do this).
This should be fixed in the new version 1.0.18.0. I did some restructuring to fix some issues with arrays. Only thing I haven't done yet is multi-dimensional arrays.
Hello Everyone ,
A new bug has been discovered in the PROJSON library, an incorrect JSON is produced when the message to be composed is a structure array, and one of its attributes is another structure:
Example that does not work :
Example that works :
testLevel1: JSONVAR;
house.rooms[1..N].Var1
Example that works :
house.room1.window.Var1
In our testing phase, we took into account previously identified bugs, in particular:
- The prohibition of having a single array in a JSON structure; it must be preceded by a JSON variable.
- The array index must start at 1.
Solution: We adopted the latter solution, defining each room flatly to avoid having a structure array whose attributes
include another structure:
house.room1.window.koeffCorrecteur
house.room2.window.koeffCorrecteur
...
house.room7.window.koeffCorrecteur
Hello everyone, I found a bug in Version 1.0.18.0.
I have a structure:
TYPE ST_JSON_TEST :
STRUCT
testList : ARRAY[0..1] OF JSONVAR;
END_STRUCT
END_TYPE
It is declared as follows:
stJsonTest : ST_JSON_TEST;
stJsonTest.testList[0].CharString := 'used';
stJsonTest.testList[1] is null;
I called the method "STRUCT_TO_JSON" with the input parameter "IgnoreNull := true".
After that, the string I got is:
'{"stJsonTest":{"testList":["used"}]}'
You can see that the position of ']' is incorrect. Does anyone know how to fix this? Thank you for any advice!
Last edit: lucawu 2025-12-11
Hi,
it seems I have fixed issues with arrays of structs.
Also added option for rootless JSON exporting/uploading
And multidimensional arrays!
https://github.com/Risele/PRO_JSON/
Hope it will work for you: I made brief tests at my structures only.
PS: made with help of AI agent, found it's quite good if you give him project/files exported as PLCOpenXML.
Thank you for your fixes. I tried version 1.0.21.0 of your library, and the Rootless feature for STRUCT_TO_JSON works great.
However, I found that it still doesn't correctly output the closing brackets when serializing an array of structures. Have you tested this kind of structure:
TYPE ST_PLANT :
STRUCT
NAME : JSONVAR;
QUANTITY : JSONVAR;
END_STRUCT
END_TYPE
TYPE ST_ANIMAL :
STRUCT
NAME : JSONVAR;
AGE : JSONVAR;
END_STRUCT
END_TYPE
TYPE ST_BIOTA :
STRUCT
PLANT : ARRAY[0..3] OF ST_PLANT;
ANIMAL : ARRAY[0..3] OF ST_ANIMAL;
END_STRUCT
END_TYPE
When using STRUCT_TO_JSON with my ST_BIOTA structure, regardless of whether my Rootless setting is TRUE or FALSE, the generated string is always missing the final ']' and the preceding '}'. I would be very grateful if you could clarify this issue for me.
Regardless, thank you again for your contribution, respect!
Just tested with your structs and seems JSON is perfectly valid.
With root:
Rootless:
The code I used:
UPD:
for top-level described array it also provides valid output, BUT only with ROOTLESS=FALSE option. It's not an error, I suppose, since nameless array could not exists in JSON.
For
output is
Last edit: risele 4 days ago