LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Decoding json with arrays

Solved!
Go to solution

Hi,

I want to decode a json with the following structure:

{"Result":1,"Message":"!! Stacker Status has been read successfully !!","Return_Values":[{"SID":1,"SName":"Stacker 1","Lat":22.46142,"Long":88.1408,"MinTemp":0,"MaxTemp":-62.5,"Time":"24-07-2024 13:48:53"},{"SID":2,"SName":"Stacker 2","Lat":0,"Long":0,"MinTemp":0,"MaxTemp":0,"Time":"07-07-2024 18:48:35"}]}

The json is returned by the following URL:  https://cescstacker.ultratech.ind.in/api/GetStatusAll?Type=json

The attached VI is thrwing errors.

Can someone guide me please

0 Kudos
Message 1 of 6
(480 Views)

Here is the JSON with better readability

{
  "Result":1,
  "Message":"!! Stacker Status has been read successfully !!",
  "Return_Values":[
    {
      "SID":1,
      "SName":"Stacker 1",
      "Lat":22.46142,
      "Long":88.1408,
      "MinTemp":0,
      "MaxTemp":-62.5,
      "Time":"24-07-2024 13:48:53"
    },
    {
      "SID":2,
      "SName":"Stacker 2",
      "Lat":0,
      "Long":0,
      "MinTemp":0,
      "MaxTemp":0,
      "Time":"07-07-2024 18:48:35"
    }
  ]
}

 Use this cluster as the LabVIEW data type:

Basjong53_0-1721898064013.png

 

Then use the JSONtext library to convert the JSON string to this cluster.

Message 2 of 6
(467 Views)

Thank you very much.

I have downloaded jdp_science_jsontext_1.8.2.122 but am unable to install it with VI package manager. How do I install a local package?

I am running LabVIEW 2015. Hopefully it is compatible.

0 Kudos
Message 3 of 6
(452 Views)

Hi,

I tried to install JSONtext but VIPM complains that it is not compatible with the current version of LabVIEW.

Would the "Unflatten from json" module as used in my VI work with your cluster?

Thanks anyway

 

0 Kudos
Message 4 of 6
(444 Views)
Solution
Accepted by topic author shantanu@india

You can also use the built-in "Unflatten From JSON" function:

json.png

It correctly outputs the result:

Basjong53_0-1721899743108.png

 

 

Message 5 of 6
(443 Views)

Worked perfectly!!

Thank you so much

0 Kudos
Message 6 of 6
(437 Views)