Host Engineering Forum
General Category => Do-more CPUs and Do-more Designer Software => Topic started by: Bolt on January 30, 2023, 12:49:17 PM
-
I have built a JSON object into a string using JSONBUILD. Now I'm trying to access it via REST API, and It returns it as a string, which is enclosed in quotes, rendering the output an invalid JSON Object, as it returns a JSON object as a string within in an object. Are there any work around for this? I don't think it's feasible to pack all the info into a UDT, as most of the values themselves are strings, so it would be somewhat kludgy to build it all as such.
-
Can you give a specific example? JSON format is an ASCII string. The only handle you have to pull, if I understand you, is the "Enclose in quotes" checkbox in the JSONBUILD "Edit Step Object Field Record" dialog.
-
Can you give a specific example? JSON format is an ASCII string. The only handle you have to pull, if I understand you, is the "Enclose in quotes" checkbox in the JSONBUILD "Edit Step Object Field Record" dialog.
I think all strings REST API responses are enclosed in double quotes, e.g. SS0 is contains the text ABC, the RESTAPI response is 5 characters long "ABC", not just the simple 3 characters ABC. It just so happens that SS0 contains JSON text.
Not sure if JavaScript can pre-process the RESTAPI response to remove the first and last characters if they're both double quotes???
-
Here's a simple example.
The request /data/json?SL0=SL0 returns:
SyntaxError: JSON.parse: expected ',' or '}' after property value in object at line 2 column 10 of the JSON data
{
"SL0":"{"Input10":false,"Input20":true,"Output30":false,"Name":"Smith","Text":"Sample"}"
}Of course a request this simple could be reconstructed with ?Input10=X10&Input20=X20&Output30=Y30&Name=SS1, but you can't do the &Text="Sample" portion, and the booleans are returned as numeric.
{
"Input10":0,
"Input20":1,
"Output30":0,
"Name":"Smith"
}
-
When I duplicate your JSONBUILD instruction, it works. I use Do-more Designer's JSON Pretty Print display, and it doesn't complain. Also, when I do the REST API function from my Internet browser, it gives results with no complaining either. And then if I select the response and copy/paste it to the online JSON Pretty Print website, it also does not complain.
Where is the syntax error coming from?
-
When I duplicate your JSONBUILD instruction, it works. I use Do-more Designer's JSON Pretty Print display, and it doesn't complain. Also, when I do the REST API function from my Internet browser, it gives results with no complaining either. And then if I select the response and copy/paste it to the online JSON Pretty Print website, it also does not complain.
Where is the syntax error coming from?
The problem is that the valid object contained within the string is being emitted as a quoted string from the REST request, but he needs the quotes stripped.
I'm looking into adding query modifier that would emit the string raw, without quotes.
-
OK, I've added a query modifier that emits the string raw, meaning, it assumes the string contains a well formed JSON object. This eliminates the leading and trailing quotes, and also the control characters for nested quotes. As long as everything contained in the string is valid JSON, this should work as expected.
The modifier is 'R' or 'r'. So "/data/json?fieldname=symbol,r" would return the raw value of string "symbol".
-
Awesome, that would be great. I can work around it for now, but I'm sure it will be useful again in the future. Thanks for the speed resolution.
Any chance you could make it work to read multiple structures similar to how it can do multiple elements? /data/json?FieldName=MyStructure0,4
-
Awesome, that would be great. I can work around it for now, but I'm sure it will be useful again in the future. Thanks for the speed resolution.
Any chance you could make it work to read multiple structures similar to how it can do multiple elements? /data/json?FieldName=MyStructure0,4
I assume you have JSON records in an array of strings, and you are expecting an array of objects from the query?
-
Yes, while not specifically JSON records in an array of strings, I would expect an array of objects. I have UDT's with short single word name or status Strings, and Bits and Words for the rest of the info, trying to keep from having to query (and further reference) them individually, /data/json?FieldName0=MyStructure0&FieldName1=MyStructure1&FieldName2=MyStructure2&FieldName3=MyStructure3 for example. If they were all in an array it would make the processing code simpler/scalable.
-
Done. Syntax is ",r#", where the modifier must come before the count. Was just a simple change to the parse to allow both a count and modifier. Previously they were mutually exclusive.
-
Excellent. Example #16325 proving Host Engineering's support blows the rest out of the water.
-
Done. Syntax is ",r#", where the modifier must come before the count. Was just a simple change to the parse to allow both a count and modifier. Previously they were mutually exclusive.
Any idea on when this updated feature can be expected? I have an application where we're polling 16 structures the "hard" way, my developer says it's slowing things down unnecessarily.
-
Done. Syntax is ",r#", where the modifier must come before the count. Was just a simple change to the parse to allow both a count and modifier. Previously they were mutually exclusive.
Any idea on when this updated feature can be expected? I have an application where we're polling 16 structures the "hard" way, my developer says it's slowing things down unnecessarily.
As soon as we stop being so lazy and release the firmware. ::)
It (2.9.9) was finished, and then we tweaked a couple of things...adding network diagnostics for some of these weird situations that have happened a few times....and just haven't gotten back to releasing it. I'll poke the bear.