LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can't unflatten from JSON

Solved!
Go to solution

Dear all,

 

can anybody with the following JSON string I want to unflatten to LabVIEW cluster/array? An online JSON validator told me the JSON string is valid, but I'm not able to unflatten. I guess the biggest problem are the different cluster names 1st_Cluster to 3rd_Cluster.

 

Any help is much appreciated.

{
"1st_Cluster":{"pair_id":1039,"price_precision":4,"amount_precision":2,"min_amount":"0.01","max_amount":"-1","min_total":"10","max_total":"-1"},
"2nd_Cluster":{"pair_id":407,"price_precision":7,"amount_precision":2,"min_amount":"35.42","max_amount":"-1","min_total":"0.005","max_total":"-1"},
"3rd_Cluster":{"pair_id":937,"price_precision":6,"amount_precision":2,"min_amount":"0.01","max_amount":"-1","min_total":"0.005","max_total":"-1"}
}

0 Kudos
Message 1 of 7
(3,799 Views)

Seemed easy enough to me.  You just need to name those 3 clusters in your master cluster.

 

My guess is that some of your inner elements are numbers, and others are strings.  So you need to set those types correctly.

0 Kudos
Message 2 of 7
(3,759 Views)

Thanks a lot for your fast help, RavensFan. 

I was able to parse all inner elements without any problem. 

The naming of the 3 clusters is another story. The naming and count of clusters in my posted question is just an example. The real data contains hundreds of clusters, all titled differently. The cluster count is changing frequently.

So, a generic solution is crucial. Can't create controls with hundreds of clusters. 

0 Kudos
Message 3 of 7
(3,752 Views)

Sorry, I didn't write that the real data contains a variable count of clusters with variable labels. 

0 Kudos
Message 4 of 7
(3,749 Views)
Solution
Accepted by Xenia1986

If you install the JSONtext library using VI Package Manager, you'll find a function that can convert your JSON into an array of item names and subclusters.  The standard JSON functions in LabVIEW are not that flexible.

0 Kudos
Message 5 of 7
(3,739 Views)

@Xenia1986 wrote:

Thanks a lot for your fast help, RavensFan. 

I was able to parse all inner elements without any problem. 

The naming of the 3 clusters is another story. The naming and count of clusters in my posted question is just an example. The real data contains hundreds of clusters, all titled differently. The cluster count is changing frequently.

So, a generic solution is crucial. Can't create controls with hundreds of clusters. 


Well that is a completely different problem and more complicated situation than what you asked.

0 Kudos
Message 6 of 7
(3,720 Views)

@drjdpowell wrote:

If you install the JSONtext library using VI Package Manager, you'll find a function that can convert your JSON into an array of item names and subclusters.  The standard JSON functions in LabVIEW are not that flexible.


Thanks a lot. This plugin made the job. I used the function JSONtext:Get All Object Items.vi to retrieve all the different cluster names into 1 array and their content into another array. Now it's pretty comfortable to build the LV cluster array I need. This library saved my day....thanks again.

 

0 Kudos
Message 7 of 7
(3,710 Views)