03-02-2020 09:18 AM
Hello all
I am switching from ini files to Json and have question how to extract data from json ?
I have different objects in my Json file and i would like to transfer them to different types of clusters or array of cluster
My Jotson:
{
"object1":[
{
"id":"a",
"param1":"text",
"param2":"text"
},
{
"id":"b",
"param1":"text",
"param2":"text"
}
],
"object2":[
{
"id":"c",
"param3":"text",
"param2":"text"
},
{
"id":"d",
"param3":"text",
"param2":"text"
}
],
"object4":{
"name":"ddd",
"param9":"number"
}
}
As you can see objects 1 - 3 are arrays of clusters witch different parameters object 4 is just a cluster.
Question is:
How to transfer my data co clusters.
Best regards
03-03-2020 04:32 AM
There's no object 3...
Of course this will be too rigid. If you ever add something to your data, old files will fail.
You should probably look into a JSON library that allows getting specific objects by traversing the JSON hierarchy or with a query.
03-04-2020 07:30 AM
Hello,
In addition to the previous answer, to make it more scalable, you can use the following example code. This can create the corresponding LabVIEW data structure (in form of a new VI) from an input JSON string, that you can use later with the Unflatten From JSON.vi and you don't have to create the type and defaults input manually.
Parse JSON to Cluster
https://forums.ni.com/t5/Example-Code/Parse-JSON-to-Cluster/ta-p/3499458?profile.language=en
Does this answer your question?