ni.com is experiencing intermittent service disruptions.

Support teams are actively working on the resolution.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Save as JSON in Labview

Solved!
Go to solution

Hi Developers,

 

       Problem Statement : I have developed code to open an existing JSON file using LabVIEW and also update the key elements (single value) depending upon the user needs.

       Now, I want to over-write the updated JSON file in the same location as before. 

      I am unable to convert the JSON Object variant back to the string by using the flatten from JSON, so that I can over-write the corresponding JSON file.

   

       Attachment : 1) JSON file 2) VI to open and update the JSON (SubVI)

3) test.vi (main VI)

 

Download All
Message 1 of 7
(9,318 Views)
Solution
Accepted by sr_nilabview

You need to use the functions provided by the library for reading the values, updating the values, and then encoding the Variant Data type containing the JSON data back to a string. See below (you'll need to add the File Write operation back in):
JSON Snippet.png

In the above, Updated JSON has the following in the indicator: {"library":{"novel":"donald","study":"physics"}}

Message 2 of 7
(9,242 Views)

Thanks izachdx the solution seems to work. The only thing the structure has to be maintained till the end.

0 Kudos
Message 3 of 7
(9,206 Views)

Hi Zach,

 

I don't find these JSON function in my LabVIEW version 2016. Is there some sort of library that I need to download? If so, please guide me through the link. 

 

Thank you!

Jatin

0 Kudos
Message 4 of 7
(8,882 Views)

You need to download these functions using VI Package Manager (VIPM). Search in VIPM for "i3 JSON" and then install that package.

Message 5 of 7
(8,877 Views)

 

JSON Snippet.png

I've just release a new JSON library, JSONtext, part of the purpose of which is to eliminate a lot of the verboseness of using the currently available 3rd-party JSON libraries.  Above is a good example, as it takes five libary subVIs to change one JSON subitem.   In JSONtext, the equivalent operation is just one subVI:

JSONpath Changing an item at a path.png

Message 6 of 7
(8,783 Views)

Hi dear,

 

Can you give example for labview 2011 or is there any method that I can try to use JSON FORMAT in labview 2011?

0 Kudos
Message 7 of 7
(7,375 Views)