RJSONIO icon indicating copy to clipboard operation
RJSONIO copied to clipboard

fromJSON with simplify=T and nulls

Open asieira opened this issue 11 years ago • 2 comments

I think I found an inconsistency in the way fromJSON handles null in strings when simplify=T. See those two examples here:

> fromJSON("[ 1, 2, 3, null, 4 ]", asText=T, simplify=T)
[1]  1  2  3 NA  4
> fromJSON("[ \"a\", \"b\", \"c\", null, \"d\" ]", asText=T, simplify=T)
[1] "a" "b" "c" ""  "d"

I would have expected the null to be converted to NA_character_, not an empty string.

Notice how those two very different JSON entries become the same (and IMHO that is undesirable):

> fromJSON("[ \"a\", \"b\", \"c\", null, \"d\" ]", asText=T, simplify=T)
[1] "a" "b" "c" ""  "d"
> fromJSON("[ \"a\", \"b\", \"c\", \"\", \"d\" ]", asText=T, simplify=T)
[1] "a" "b" "c" ""  "d"

asieira avatar Mar 17 '14 13:03 asieira

Thanks. I committed a minor change which seems to resolve the issue and leave other things working the way the previously did. Thanks.

duncantl avatar Mar 17 '14 14:03 duncantl

Thank you for fixing this so quickly, and for providing this very useful package in the first place. :)

asieira avatar Mar 18 '14 13:03 asieira