duncantl / RJSONIO

Serialize to and from R and JSON, JavaScript Object Notation
http://www.omegahat.org/RJSONIO
Other
25 stars 68 forks source link

fromJSON with simplify=T and nulls #10

Open asieira opened 10 years ago

asieira commented 10 years ago

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"
duncantl commented 10 years ago

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

asieira commented 10 years ago

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