Table of Contents
34 JSON
JSON (JavaScript Object Notation) is a lightweight data-interchange format (from https://json.org). It is widely used to convert data types and structures into a text (UTF-8) representation that is easily readable by machines and humans.
Usage with LabVIEW
LabVIEW has built-in functions to convert data types into a JSON string and back. You can find these nodes in the “Programming” pallet under “String/Flatten Unflatten String/”.
These functions can be used without installing any other packages. The downside is, that the functionality is very limited.
Recommended JSON Library
For everything more complex as a simple Cluster, we use the JSONtext library (https://www.vipm.io/package/jdp_science_jsontext/). This library offers a comprehensive set of functions to convert LabVIEW data types into JSON and JSON string into LabVIEW. Especially, extracting only parts from large JSON strings is very convenient with the usage of JSON-Path (https://en.wikipedia.org/wiki/JSONPath) expressions.
Tips and Tricks
-
Use the “Find *” VIs to find and get parts of a JSON by a JSON Path expression.
-
JSONtext support comments in JSON files.
-
Most functions don't validate the whole JSON string for validity and only return a default value. To check if a string is valid JSON, use the “Reformat” VI.
