LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Unflatten from JSON problem

Solved!
Go to solution

Hi all. I would like to extract the 'stdout' value from the following JSON string:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": [
       0,
       {
           "code": 0,
           "stdout": "{\"up\":true,\"pending\":false}}\n"
       }
   ]
}

This is a valid JSON string (checked with online validators), however I don't find a way to convert it to a LabVIEW cluster, probably because of the unnamed constant in the 'result' array.

 

This is what I tried:

json-problem.png

Unflatten from JSON throws an error -375005: Type mismatch between JSON and LabVIEW.

Which is reasonable, because there is no 'unnamed' field. Honestly, I don't know what else to try.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 1 of 6
(135 Views)
Oh wow, this is not a typical LV data structure, if you notice carefully, the "result" array is not of same type of elements, element 0 is numeric whereas element 1 is a dict.

You can use the https://www.vipm.io/package/jdp_science_jsontext/ to navigate to each element in that array and extract the value.

Which application conjured such an illogical data structure?
Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution
Message 2 of 6
(124 Views)
Solution
Accepted by topic author pincpanter

The data structure is not representable in LabVIEW, but you can pick it apart using the path input.

JSONText also cannot handle the array as an array, although I am almost sure it could at one point in the past.

 

snip_json_weird_array.png

Message 3 of 6
(111 Views)

Thank you. Actually I tried with paths, but... in the wrong way. Honestly I did not realize that the "array" could contain heterogenous data, having in mind LabVIEW arrays.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 4 of 6
(87 Views)

@santo_13  ha scritto:
Oh wow, this is not a typical LV data structure, if you notice carefully, the "result" array is not of same type of elements, element 0 is numeric whereas element 1 is a dict.

You can use the https://www.vipm.io/package/jdp_science_jsontext/ to navigate to each element in that array and extract the value.

Which application conjured such an illogical data structure?


Thank for the answer. This is basically the output of a console application resident on a "smart" router, called via a json-rpc protocol. Actually I don't know what is the role of the 0 constant: I would think it's the return code of the command, but there is a seemingly more explicit "code" field.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 5 of 6
(84 Views)

@cordm wrote:

The data structure is not representable in LabVIEW, but you can pick it apart using the path input.

JSONText also cannot handle the array as an array, although I am almost sure it could at one point in the past.


 If you ask for the "Result" item and parse it into JSON array elements it works fine:

 

Example_VI.png

0 Kudos
Message 6 of 6
(75 Views)