Showing results for 
Search instead for 
Did you mean: 

Null character in Flatten To JSON Function


I'm using the Flatten To JSON Function to pass a JSON string to an http client POST.  I need to pass a null to the Flatten To JSON as an empty string data value.  I've tried a string constant with simply null, just as the JSON spec calls out an empty data value.  I've also tried the string constant (with no characters in the constant), empty string constant, the space constant, and maybe even a few other.


When using all of the above techniques, the resulting JSON string returned is either ["attribute":"null"], or ["attribute":""], indicating that is is being interpreted as string data.


How do I get the straight up JSON null to be read by the Flatten To JSON Function and output as ["attribute":null] as should be for an empty string data value?

0 Kudos
Message 1 of 5

Not sure if null is supported in the flatten case. Should be an easy fix though. Can you use the "Search and Replace" function on the resulting JSON string to insert null wherever you need it?


For example, you could use a string data type for the null element with "null" as it's value, and then remove the quotation marks around "null" after you've flattened:



0 Kudos
Message 2 of 5

This is the work around method I'm using right now to get it in the correct state now.  I haven't found a situation where this will cause a problem in my application yet, but my fear is one may crop up eventually.  I was wondering if there is a better, JSON supported solution out there.

0 Kudos
Message 3 of 5

Not sure if it is better but there were several JSON libraries before NI came out with their own, here is one of them.


That being said I wouldn't be surprised if it too had issues with a null since that is usually a terminating character for various LabVIEW string functions.

0 Kudos
Message 4 of 5

JKI JSON library supports flattening and unflattening null values, empty arrays and empty clusters.

Tomi Maila
0 Kudos
Message 5 of 5