03-13-2023 10:36 AM
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
03-13-2023 10:57 AM
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.
03-13-2023 12:04 PM
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. |
03-13-2023 12:37 PM
Here are the clusters in question, particularly the first two.
Girish
03-13-2023 01:47 PM
03-13-2023 01:55 PM
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
03-14-2023 04:28 AM
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.
03-14-2023 09:01 AM
I have to correct myself. The cluster data cannot be read this way. Sorry.