LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

JSON parser

Here is my first attempt to produce an equal result to the original code. I should be making a few more improvements with white space and the way arrays are handled.  I few issues here before you download this VI.  First, you need to have the OpenG Labview Data Library.  If you don't have it, you can get it from VIPM.  Second, you need to have the VIs from Github.  A link to the JSON repo from Philmod is posted above.  The attached VI can then be used inside "Test cluster2json.vi" to show the same result as the control reference based solution.

0 Kudos
Message 21 of 27
(1,850 Views)

Just an idea: have you considered leveraging OpenG's "Format into String" (with default formating) instead of your innermost case structure?  It handles a large array of types, including timestamps, enums, paths, complex numbers, etc., which would be a lot of work for you to add explicitly.  

 

-- James

Message 22 of 27
(1,838 Views)

Thanks James, I think that is a good idea.  My plan was to get rid of the innermost case structure all together.  I would like to see arrays handled in the same manor as other data types.  To do that, arrays would be pushed on to the stack (queue) much like nested clusters. But using the "Format into String" might work just as well.

0 Kudos
Message 23 of 27
(1,834 Views)

James,

You were right.  Its much nicer now.

 

Cluster2Json (byvalue).png

Message 24 of 27
(1,825 Views)

Good work.

 

One extra optional suggestion.  The OpenG tools work by flattening the variants and parsing.  Flattening can be expensive for large items.   Often when one uses several Data Tool VIs in sequence, one is actually flattening the same data more than once.  For example, you are calling both "Get Array Element TDEnum" and "Array to Array of VData" on the same thing.  Both of these call "Varient to Header Info", and so the data is flattened twice.  By looking inside those VI's at the lower-level functions, one can usually come up with code that avoids duplicated operations (and often with fewer data copies).  In other words, one can make it higher performance.  Often this isn't worth the effort, but it might well be for a messaging system like JSON depending on your application.  One can always leave this improvement till later.

 

-- James

Message 25 of 27
(1,820 Views)

James,

Thanks for your advice.  Here's the latest VI.

0 Kudos
Message 26 of 27
(1,818 Views)
Hello, I wrote the original code that the github code is based on. I have no problems rewriting or modifying it. I am on my phone but will look at your solution as soon as I can.

Have you considered asking the OpenG team to distribute this? It is a perfect addition. Also I would be very impressed if you could implement the opposite and unflatten JSON to a cluster.
=====================
LabVIEW 2012


0 Kudos
Message 27 of 27
(1,791 Views)