LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Cluster of clusters to JSON

I would like to create a JSON string of a cluster of clusters. When I connect the cluster to Flatten to JSON I get a wire error "Polymorphic terminal cannot accept this data type". What is the procedure for flattening cluster of clusters? 

Thank you. 
Girish

0 Kudos
Message 1 of 8
(1,608 Views)

A cluster within a cluster should not be a problem. The reason is another element that LabVIEW refuses to flatten, like a timestamp. We need to see your cluster to see which item is the problem.

I would recommend a third-party JSON library, since they don't have this limitation. Personally, I like JSONText.

0 Kudos
Message 2 of 8
(1,601 Views)

From the help:

anything contains the data you want to convert to a UTF-8 JSON string. This input accepts arrays and clusters of Booleans, floating-point numbers, and strings. anything can also accept an array of clusters, or a cluster of arrays, of these data types. This input does not support other data types, such as enums, refnums, file paths, and fixed-point numbers.
G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 3 of 8
(1,581 Views)

Here are the clusters in question, particularly the first two. 

Girish

0 Kudos
Message 4 of 8
(1,568 Views)

Hi girish,

 

did you read Yamaeda answer and the help mentioned in this message?

Did you check your clusters for those datatypes not supported by the ToJSON function???

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 8
(1,553 Views)

Yes, I read the Yaemeda's response. I was wondering if there is another way to write and read clusters in a cluster. I will look at the third party package you had suggested. I also found out to my surprise that Flatten to XML does not give an error when I connect the same cluster. I am trying to see if that will work. 

Thank you. 

Girish

0 Kudos
Message 6 of 8
(1,550 Views)

There is at least another way to read them. In the Variant section there are type information VIs. One that gets you an array of 1st level elements which you could index to get an array of 2nd level elements, etc. Then there is a VI to get the cluster element name and the variant to data VI to convert the cluster element's data. 

0 Kudos
Message 7 of 8
(1,504 Views)

I have to correct myself. The cluster data cannot be read this way. Sorry.

0 Kudos
Message 8 of 8
(1,491 Views)