JKI-JSON-Serialization
JKI-JSON-Serialization copied to clipboard
JSON ignoring single variant in a cluster
Example VI: JSON Test ignoring single variant in a cluster.vi.zip
See original bug report on JKI forums.
Notice how the "bridge_data" (variant that's inside the cluster) does not show up in the JSON data.

However, we I add another element next to the variant, so it's not the only element in the cluster, then we see "bridge_data" in the JSON string.

It seems to be related to a LabVIEW "feature" that transforms a cluster of one element to the element itself when you flatten it. In this case, it must be interpreting the variant as matching the cluster instead of the first element of the cluster.
@jimkring I found the error to originate in the "JSON Serializer.lvclass:Cluster Info.vi" which calls the OpenG "Array to VData" method. This OpenG method errors out when the payload is not a cluster. When it is a cluster, it extracts the elements instead of returning a 1-element array containing the variant.
This seems like a LabVIEW bug to me... and it has to do with type propagation. I was able to reproduce a very fundamental inconsistency as shown here.
https://www.youtube.com/watch?v=XevSM1Bj4l4
I will report this bug in a well documented way to NI, but I thought I'd drop it here because this is the cause of the problem. Once I had propagation correct, I was able to get the cluster of an empty variant to show up as a single-element variant inside a cluster (not shown here).
Thanks @francois-normandin. I've also posted more info here on the JKI JSON forum, a bug report on LAVA, and I've let NI know. The fix is for users to add a To Variant function before calling Flatten to JSON String, since the bug is in the coercion dot.