LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

JSON parser


@Philmod wrote:

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


For the second question, you need your subVI to take a control reference in and not the actual cluster. From the calling VI you would right click on a cluster and create a reference. Wire that reference to your cluster2json VI. The easiest way to create the control is to right click on the green Controls[] wire and select create control. Delete your cluster and it's property node and instead wire the new control to the loop.

 

For the first question you could make the subVI reentrant under execution/properties. In your "cluster" case you place an instance of itself inside. You would wire the reference out from the property node on the left of the case structure to this instance. You also need a property node for the name of the cluster (text/label).

 

Let me know if you have any questions.

 

 

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


0 Kudos
Message 11 of 27
(2,654 Views)

You also need a to more specific class. Like this

 

JSON.lvlib_cluster2json_BD.png

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


0 Kudos
Message 12 of 27
(2,652 Views)

I redid some stuff in your VI. One point that is not really related to your problem is about connector panes. I really don't like to change from the default connector pane. I also like to pass references through VIs. I don't mind unused connectors. It is always a pane (pun?) when I want to add a control or indicator and have to change the connector pane and relink. Enough about that Smiley Happy

 

I changed your array2json so that it will be able to determine the type of array. Right now it only has a case for DBL but you can add one for string. See the Test cluster2json VI that I added.

 

 Edit: This also does not escape the special characters for strings as defined at http://json.org.

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


0 Kudos
Message 13 of 27
(2,642 Views)

Thank you so much Steve!!

 

But I didn't catch you about the special characters espacing for strings.  I implemented: \ --> \\ and " --> \".  I have to do the same for the LabView backspace, newline, carriage return, tab, ... ?

0 Kudos
Message 14 of 27
(2,608 Views)

I don't know if you're familiar with Github, but I push the library there (https://github.com/Philmod/Labview-JSON).  It will be easier to contribute to the VIs.

0 Kudos
Message 15 of 27
(2,589 Views)

Yes, that's what I mean. Here is a VI, but it doesn't support escaping unicode.

 

 

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


0 Kudos
Message 16 of 27
(2,579 Views)

Stumbled across this thread while researching JSON with Labview.  I might have use for something like this for websockets but I need it to work in Labview Real-Time.  The code posted on Github would have to be refracting to a value based approach instead of control referenced based.  Labview Real-Time does not support control references.   Any objections to me contributing to this code and making it work for Labview Real-Time?

0 Kudos
Message 17 of 27
(2,490 Views)

I would be interested in your solution!

0 Kudos
Message 18 of 27
(2,466 Views)

@dwisti wrote:

Stumbled across this thread while researching JSON with Labview.  I might have use for something like this for websockets but I need it to work in Labview Real-Time.  The code posted on Github would have to be refracting to a value based approach instead of control referenced based.  Labview Real-Time does not support control references.   Any objections to me contributing to this code and making it work for Labview Real-Time?


Just to repeat my previous suggestion: make sure you peruse the "OpenG LabVIEW Data Tools" as they make stuff like this pretty easy.  And they work on Real Time.

 

-- James

0 Kudos
Message 19 of 27
(2,462 Views)

James,

I totally agree.  I don't think I would be able to "not" use OpenG to produce a value based solution.

 

David

0 Kudos
Message 20 of 27
(2,453 Views)