Skip to content
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

Bug in toJSON with lists containing vectors of length zero #13

Open
kevinushey opened this issue May 3, 2014 · 4 comments
Open

Bug in toJSON with lists containing vectors of length zero #13

kevinushey opened this issue May 3, 2014 · 4 comments

Comments

@kevinushey
Copy link

@yihui and I are seeing the following behavior:

> cat( toJSON( list(x=1, y=character(0)) ) )
{
 "x":      1,
"y":      1 
}

This is because unlist is used to collect results, but because the y element is empty, it is dropped and then the element 1 is recycled.

@kevinushey kevinushey changed the title Bug in toJSON Bug in toJSON with lists containing vectors of length zero May 3, 2014
@duncantl
Copy link
Owner

duncantl commented May 3, 2014

Thanks. I see the problem and I'll think about how best to fix it.

@duncantl
Copy link
Owner

duncantl commented May 3, 2014

This should be fixed now in the github source. We'll see if it breaks anything before pushing it onto CRAN. Thanks.

@apontejosea
Copy link

I think problem still persists. For instance:

cat(RJSONIO::toJSON(list(C=as.numeric(NULL))))

produces:

{
 "C":  
}

Which is invalid json. I would expect:

{
 "C": null 
}

Other than this, excellent package.

@kevinushey
Copy link
Author

FWIW this only affects numeric vectors:

> cat(RJSONIO::toJSON(list(C = numeric(0))))
{
 "C":  
}> cat(RJSONIO::toJSON(list(C = integer(0))))
{
 "C": [] 
}> cat(RJSONIO::toJSON(list(C = character(0))))
{
 "C": [ ] 
}> cat(RJSONIO::toJSON(list(C = logical(0))))
{
 "C": [] 
}

(aside: some whitespace is emitted within the brackets for character vectors; not a showstopper but it'd be nice if empty vectors were handled consistently)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants