LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Json Get object to cluster

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 

0 Kudos
Message 1 of 3
(2,746 Views)

JSON 2.png

 

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.

Message 2 of 3
(2,680 Views)

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?

Message 3 of 3
(2,649 Views)