LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

JSON parser

Hello,

 

As the JSON format becomes more and more used, I need to parse my datas in JSON (in the same way that the XML parser).

 

Is there anything available?

 

Thank you,

Philippe

Message 1 of 27
(6,275 Views)

There are utilities to convert between JSON and XML. You can start here. You can probably find or create a dll which you can call from LabVIEW to convert JSON to XML and then use the XML parsing that LabVIEW offers or use EasyXML. It would be nice if LabVIEW had a function to flatten and unflatten to JSON. There is an idea on the exchange for that.

=====================
LabVIEW 2012


0 Kudos
Message 2 of 27
(6,268 Views)

Thank you for the answer.

 

I had already found these topics, but it sounds very bad to flatten first to XML and then to JSON.

 

It's strange that nobody already did a VI, no?

 

Regards,

Philippe

0 Kudos
Message 3 of 27
(6,239 Views)

I did a VI that encodes a cluster to JSON, but not the other way around. If that is all you need then I could explain how I did it. I cannot post the VI because it is something that I was paid to write so I don't own it.

 

Does anyone have an idea of how to go about writing an unflatten from JSON VI? How do you write something like the unflatten from XML where you wire a type to it and get the type out? Is this an xnode?

=====================
LabVIEW 2012


0 Kudos
Message 4 of 27
(6,227 Views)

It would be great to know how you made it!!

 

I don't need to decode JSON to whatever labview variable, I just need to send JSON from labview to the web.

0 Kudos
Message 5 of 27
(6,223 Views)

The secret is a little jewel hidden in vi.lib that takes a control reference and returns an enum for the type. Start with the attached vi. You will have to add a string shift register for the JSON output and build it up each iteration of the for loop. Your JSON object names will be the name of the controls in the cluster.

 

 

=====================
LabVIEW 2012


Message 6 of 27
(6,220 Views)

@Steve Chandler wrote:

Does anyone have an idea of how to go about writing an unflatten from JSON VI? How do you write something like the unflatten from XML where you wire a type to it and get the type out? Is this an xnode?


OpenG LabVIEW Data Tools should allow one to write something to get from JSON to a Variant Cluster.  You'd need to convert the variant to the actual type outside your VI.

0 Kudos
Message 7 of 27
(6,203 Views)

Thank you so much!!  I will make it and then send it back to you to get your opinion!

 

Regards,

Philippe

0 Kudos
Message 8 of 27
(6,180 Views)

Hi Steve,

 

I wrote some code, but I still have some problems: 

  - I would like to use the cluster2json vi recursively if there are clusters inside the main cluster, but how I can get back the clusters from the variant?

  - What kind of input variable I have to use in cluster2json in order to use any kind of cluster (and not a defined type)?

 

Regards,

Philippe

Download All
Message 9 of 27
(6,150 Views)

Here is the lib file.

0 Kudos
Message 10 of 27
(6,143 Views)