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?
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?
Check any of your JSONVARs. The Names variable contains an array of the variable name divided by level. For example, if the variable path is Application.Test_SingleVar_PRG.colour, then the array will contain [3] 'Application' [2] 'Test_SingleVar_PRG' [1] 'colour' The ApplicationLevel property should be the array index which contains 'Application', in this case 3. This is all figured out in the JSONVAR.FB_Init method. The other place to check is JSONVAR.VarName, which is the full instance path of...
Correct. In an actual use case I think the compose and parse would happen on different machines.
SOLVED SEE REPLIES NOT A BUG, Different thinking approach Hello, There is still a bug within the Json_TO_Struct FB. Within the method MatchAllLevels: The EXIT Statement was in the wrong place within the for loop. As the loop needs to be exited when a match is found. The bug caused the matchalllevels method to always feedback the value false due to the exit statement. When placing the exit after match is set to true the values are parsed into the struct. --------------------------------------OLD-----------------------------------------------------------...
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.
sFileContentsWrite_Struct : ST_TEST; sFileContentsWrite_Struct_Json : ST_TEST_Json; sFileContentsRead_Struct_Json : ST_TEST_Json; sFileContentsRead_Struct : ST_TEST; sFileContentsWrite_Struct_Json.fReal.Number := sFileContentsWrite_Struct.fReal; sFileContentsWrite_Struct_Json.nInteger.Integer := sFileContentsWrite_Struct.nInteger; sFileContentsWrite_Struct_Json.sText.CharString := sFileContentsWrite_Struct.sText; sFileContentsWrite_Struct_Json.fLreal.Number :=sFileContentsWrite_Struct.fLreal; s_fbJsonParser(...
If you can post an example I can test it here.
OKay but then there must be another error, as after the change the functionblock read all the values into my local struct. Without the fix my local struct stayed empty all the time.
The EXIT is in the correct place in the original, this is not a bug. The loop returns FALSE and exits on the first occurrence of a mismatch. If there are any mismatches, there is no point in evaluating the rest of the array. All levels must match for this method to return TRUE.
Hello, There is still a bug within the Json_TO_Struct FB. Within the method MatchAllLevels: The EXIT Statement was in the wrong place within the for loop. As the loop needs to be exited when a match is found. The bug caused the matchalllevels method to always feedback the value false due to the exit statement. When placing the exit after match is set to true the values are parsed into the struct. --------------------------------------OLD-----------------------------------------------------------...
Hello. I have an error in JSON_TO_STRUCT when trying to get JSON from string: 'Check application name in GPL_JSON.APPLICATION_NAME'. But I didn't change my application name, it's still "Application". What's wrong?
Home
Home
Home
Thanks a lot for the update! So my project worked with the old version of the library for you? That is very strange. Need to check it from my side then.
Home
I've released v 1.0.0.15 (link above). I tested your project as well as several of mine, with various different orders of the variables and it's working for me. The code on line 100 was correct, as far as how the FOR loop/EXIT worked, but I refactored some of that to make it easier to understand.
Home
I'll attach a project to this message. I am using the HTTPClient library to read a JSON string through a HTTP request. I left you a sample string that I want to parse in the code to demonstrate the issue. You can see that the key-value pairs do not match up between the string and the JSON struct. Hope that helps.
I'll attach a project to this message. I am using the HTTPClient library to read a JSON string through a HTTP request. I left you a sample string in the code to demonstrate the issue. Hope that helps.
I think I have reproduced something like this, but it would be helpful if you can provide a test program, or at least a JSON string that demonstrates it.
If you will tackle it again, here's another issue I discovered. The JSON string I want to parse contains some nested arrays and objects. It came to my attention, that proper parsing only works when the key-value pairs on the lowest level (inside arrays) are sorted alphabetically. Otherwise, the values can be assigned to the wrong keys. I didn't check the code further to find what causes this, but maybe you will have an idea? Otherwise it seems to do what it does, so thanks a lot for sharing!
awesome! thank you sir.
@bnewman as far as I'm concerned, it's released under the terms of "it's on the internet so people can do whatever the heck they want with it". I think I had to pick a license when I put it on here, but I don't actually know anything about GPL, nor do I care. Use it, modify it, copy it, put it in your own projects, contribute to it, credit me. Or not. Whatever you like. I just changed the licensing to both MIT and Unlicense. I honestly don't know the difference, but I hope that makes it easier for...
I haven't had a lot of time to do anything with this for several months, but thanks for the input. It does look like a bug, I'll try to take a closer look at it next week.
@bnewman as far as I'm concerned, it's released under the terms of "it's on the internet so people can do whatever the heck they want with it". I think I had to pick a license when I put it on here, but I don't actually know anything about GPL, nor do I care. Use it, modify it, copy it, put it in your own projects, contribute to it, credit me. Or not. Whatever you like.
Will you please rerelease this under MIT or MPL2? GPL is a cancer.
I am aware that this thread is three years old, but I ran into the same issue and could not resolve it. Does anyone know what can cause this? Thanks in advance! Edit: After some more tinkering, I found the issue preventing proper parsing of the JSON string. For this the library function JSON_TO_STRUCT (FB) has to be adjusted from row 100. The original implementation is as follows: //Match name and array index. Array index will be 0 if the current name:value is not part of an array IF MATCH_NAMES(JSONVars^[jsonvarindex].Names[nameindex],...
I am aware that this thread is three years old, but I ran into the same issue and could not resolve it. Does anyone know what can cause this? Thanks in advance!
Home
Home
Home
Home
Hello, have you managed to solve this case? I am struggling with the same issue. Thanks.
I'll see if I can find some time to test this out.
good catch, I'll add that to future versions
Hi, I haven't had time to test it, but have you tried recordset :ARRAY [1..1] OF strPGTdataSet;
Hello, I have a problem parsing a JSON string and I need help. The string I receive: '[{"device_id":"1","pgt_id":"2","usertag":"3","hgl":"4","ls":"5","rs":"6","erg":"7"}]' The struct I devined: TYPE strPGTdataSet: STRUCT device_id :JSONVAR; pgt_id :JSONVAR; usertag :JSONVAR; hgl :JSONVAR; ls :JSONVAR; rs :JSONVAR; erg :JSONVAR; END_STRUCT END_TYPE The FB I call: ParseJSON( Execute:=xParseJSON, JSONString:= ADR(hTTPClient_0.httpResult.sContent), JSONStringSize:= SIZEOF(hTTPClient_0.httpResult.sContent),...
Hi, you should add (GPL_JSON.MAX_VALUE_SIZE) on this string. Because if bigger value sizes it runs into faulty parse. TYPE JSONNAMEVALUE : STRUCT Value: STRING(GPL_JSON.MAX_VALUE_SIZE); //value of the object at this level END_STRUCT END_TYPE Greetings
Hello Guys, I believe there's an issue with nested structs on all verions. For example: TYPE stDebugJson : STRUCT timestamp : JSONVAR; messageType : JSONVAR; //message : JSONVAR; //works fine with setting MaxLevel to 1 message : stDebugMessageDetails; // missing end bracket END_STRUCT END_TYPE stDebugMessageDetails is just another type: TYPE stDebugMessageDetails : STRUCT message : JSONVAR; END_STRUCT END_TYPE The output looks like: {"debugMessageJson":{"timestamp":"2020-03-06T23:27:22.966Z","me...
Hello Guys, Thanks for releasing this. Using the latest version 1.0.0.8, I noticed that it also outputs extra entries "loggerInstance" and "debugMessageJson". How do I remove this as my message should only look like: { "timestamp": "2020-03-06T22:57:48.902Z", "messageType": "DEBUG", "message": "this is a test for the logger debug code" } Version 1.0.0.8 produces: { "loggerInstance": { "debugMessageJson": { "timestamp": "2020-03-06T22:57:48.902Z", "messageType": "DEBUG", "message": "this is a test...
Home
Home
version 1.0.0.7
It's cleared.
One Question. It is possible to create the following JSON String. I don't kwow, how it works with the example. The problem is the array of different kinds of objects. With 3S-library it is possible. And it is a valid JSON-String. { "requestId": 1, "name" : "getPosition", "params" : {"node":10000220}, {"units": {"length":"mm","angle":"deg"}}, {"origin":1002} } Thanks a lot.
Added some fixes for special formatting in the JSON file:
Merged changes from CODESYS SVN back to library file and built the package
version 1.0.0.2
Home
Added package
Moved CODESYS lib two levels deeper to make space for the the package and potentially more projects or files.
Add initial directories