New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Encoding of NULL value #130
Comments
I just found https://github.com/jeroenooms/jsonlite/blob/master/R/toJSON.R#L21-L24 and realized this is a deliberate attempt to avoid generating "invalid" JSON. However, it turns out that if we are strict, only arrays and objects are valid JSON. No single value (null, string, numeric, etc) is valid JSON. So for consistency if we don't allow
I don't see any reason to make an exception just for |
Well the idea was that at least with the default settings |
But if that was the case, then no JSON values (as opposed to arrays or objects) should be generated either, such as strings or numbers, right? Also, I believe that allowing just values to be generated is the standard behavior of all JSON libraries I've seen on other languages. For example, in Python:
My humble suggestion would be that jsonlite follow this same behavior, and treat NULL the same way it treats string and numeric values. |
Exactly, the default arguments in > toJSON(pi)
[3.1416]
I don't disagree, but I'm reluctant to make breaking changes at this point. I have a hard time remembering why we added this special case but there probably was a good reason to avoid |
Of course, breaking changes are painful and I totally understand your reluctance. :) For the record, I would be perfectly happy with having |
Thanks again for the awesome package and let me know if there's anything I can do to help. |
OK it is now changed: debfe97. Hopefully nobody was relying on this edge case. |
This is now on CRAN in jsonlite 0.9.22. Just want to emphasize that we usually never change behavior of Also note that a trick for users that want to use > toJSON(I(123), null = "null", auto_unbox = T)
[123] > toJSON(I(NULL), null = "null", auto_unbox = T)
[] This is what e.g. shiny does, so they were unaffected by this edge case in the first place. |
This is unexpected:
Shouldn't the output on this case be the string
null
instead? It would certainly be more consistent with the behavior of fromJSON:The text was updated successfully, but these errors were encountered: