JSON Toolkit for LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

NULL as data in DBL and Strings?

I am not sure if it's JSON-kosher (although, I assume it is as it's being produced by JSON from Fog Creek Software), but I am seeing "null" (without quotes) come back in a couple JSON responses (one which is supposed to be a numeric date, and the other in a string field.  The string is delivered with quotes when it exists, but only null without quotes when it's empty

I modified the library on my Dev machine to handle this (added "JSON NULL" case to both String and DBL within "Set Value of LabVIEW Base Type.vi").  For Strings I pass an empty, for DBL I pass NaN.

What do you guys think about adding this support?  I can do it and send you the file.

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

Hi Jed_Davidow,

I am hesitant to integrate this technique because one property of JSON Tree to LabVIEW Type.vi and LabVIEW Type to JSON Tree.vi is that they should be able to work in a one-to-one fashion as discussed in the other post. If it was changed so that null values become empty strings then when converting back to json data it would be difficult to distinguish between null values and empty strings breaking the one-to-one behavior. In addition, if in the future more robust types are used to represent numeric values it would be difficult to utilize other types than floating point types (ex. integer types in LabVIEW do not have a NaN representation).

What may be possible it to create two modes for filtering JSON data using a LabVIEW type, a strict mode and a relaxed mode. The strict mode will enforce the one-to-one behavior and the relaxed mode will not enforce a one-to-one behavior which would allow for convenience functions like parsing null values as empty strings, etc. Any suggestions on this type of implementation?

However, the null value is a valid value in JSON and the library can be used to handle them correctly with the low level VIs. The following example shows how to extract a string and a numeric that replaces null values with a default value and is the approach I would recommend in this case to keep library compatibility:

handleNull.png


Milan
0 Kudos
Message 2 of 2
(5,771 Views)