LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Feedback- JSON text

Solved!
Go to solution

I am new to JSON in general, trying to use JSON text to extract some info from my configuration file. I feel like there is an efficient way to do this. Basically, trying to create a VI to extract info based on the key & value pair I pass in. it works but looking to see if there is an efficient way.

 

LVEnt_0-1786215714178.png

 

attached json as a txt file.

0 Kudos
Message 1 of 11
(558 Views)

Change the cluster array to a Map and it'll be cleaner. You also don't need the shift register and build array, just concatenate the array on the output (not needed with a map).

Something like this:

Yamaeda_1-1786355316602.png

 

 

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 11
(422 Views)

@Yamaeda wrote:

Change the cluster array to a Map and it'll be cleaner. You also don't need the shift register and build array, just concatenate the array on the output (not needed with a map).

Something like this:

Yamaeda_1-1786355316602.png

 

 


Be carefull here, in the author implementation, all key / value pairs are concatenated. There are duplicates for each "signal_generators".  In yours, all key value pairs are inserted into 1 map, discarding previously already inserted key values.

@LVEnt it would be easier to help you if we have a JSON example / schema to work with. 

0 Kudos
Message 3 of 11
(386 Views)

I'm not sure how many records you have or how much access you need, but a SQLite database might be a nice choice. It's a "database in a file" format so you don't need a server or anything. The author of the JSONText library you're using also has a SQLite library and it's great.

0 Kudos
Message 4 of 11
(365 Views)

Depending on how flexible you need this (like does "signal_generators" need to be a runtime input?) you could do all the filtering in LabVIEW after one JSON conversion.

avogadro5_1-1786378791228.png

 

0 Kudos
Message 5 of 11
(351 Views)

I have a json config file attached to my OP.

0 Kudos
Message 6 of 11
(342 Views)

I want to have the flexibility to add or remove a field in the json, so my cluster cannot be a constant. This is one reason I started looking into jsontext.

0 Kudos
Message 7 of 11
(340 Views)
Solution
Accepted by LVEnt

Here's a different implementation that uses "find item.vi" to avoid one loop layer and does not create array elements that will not be needed.

avogadro5_0-1786382090698.png

For this to be somewhat robust you should try to raise an error (or otherwise handle) if multiple items or 0 items match the search criteria

Message 8 of 11
(318 Views)

can you attach the VI please?

0 Kudos
Message 9 of 11
(297 Views)

@LVEnt wrote:

I have a json config file attached to my OP.


Sorry, I missed it 😅

0 Kudos
Message 10 of 11
(228 Views)