Sign Up

Details

When parsing JSON strings where a value is set to null, the following error is generated:
Error 402844 occurred at JSONtext.lvlib:Scalar JSON text to Variant (not inlined).vi:5750001

Since the use of null is an official part of the RFC 8259 specifications it seems a bit unnecessary to not handle it more gracefully.

When a LabVIEW type has been provided, as long as the parameter name matches, the null should simply be ignored/default value used. At most a warning could be generated but it is not really an error.

Test JSON:
{
"some_string": "",
"something": null
}

Comments

James Powell Question: why are you connecting the error out wire at all if you just want to use default values when there is a type mismatch? Other Users sometimes ask me for the opposite behaviours, with even stricter requirements (like "something" being missing also being an error) so it is difficult to keep everyone happy.
 •  Reply1 day
Kjell Edmund Ims Fair enough that it is one of "those" situations. In my case I wanted to know that the JSON was valid (using reformat as a JSON validation check). Of course I can work around this in a few different ways.. Maybe if there was a separate "Valid JSON syntax" boolean output? Clearly I am biased, but I would tend to lean towards "This is a JSON tool" and "if it is valid JSON syntax it is ok" and it should not necessarily care if an item is "missing" as that is much more application specific. "Is it valid JSON syntax" seems more natural (to me) than trying to handle all sorts of "other" conditions. :)
 •  Reply1 day
James Powell "forty-five" and true are both valid JSON Syntax; would you want them to be accepted as default=0 numbers without error?
 •  Reply1 day
James Powell BTW, you could also make your own wrapping function that suppresses Error Code 402844, "Input JSON cannot be converted to requested LabVIEW Data Type", since Syntax errors are other codes.
 •  Reply1 day
Kjell Edmund Ims First, I love using your tool and it is one of my most used packages! :) Secondly, I agree this is complicated, and I will accept that it wont be changed because any change will be "wrong for someone". Best case it would differentiate between JSON Syntax errors and LabVIEW Type missmatch errors.. but yeah. I get it. Thanks again for engaging in conversation!
 •  Reply1 day

Please sign in to leave a comment.