annuler
Affichage des résultats de 
Rechercher plutôt 
Vouliez-vous dire : 

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 Compliments
Message 1 sur 5
6 743 Visites

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:

 

Capture.JPG

0 Compliments
Message 2 sur 5
6 732 Visites

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 Compliments
Message 3 sur 5
6 646 Visites

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

 

https://lavag.org/files/file/216-json-labview/

 

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 Compliments
Message 4 sur 5
6 636 Visites

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

 

jki.net/tools#json

--
Tomi Maila
0 Compliments
Message 5 sur 5
6 334 Visites