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

toJSON(auto_unbox=TRUE) can generate invalid JSON #71

Closed
wch opened this issue Feb 28, 2015 · 1 comment
Closed

toJSON(auto_unbox=TRUE) can generate invalid JSON #71

wch opened this issue Feb 28, 2015 · 1 comment

Comments

@wch
Copy link
Contributor

wch commented Feb 28, 2015

I just switched Shiny to jsonlite and in some rare test cases ran into this bug. (We previously switched to jsonlite but backed it out for a maintenance release.)

toJSON('foo', auto_unbox=TRUE)
# "foo"

I think it makes sense to special-case this so that it returns ["foo"].

@jeroen
Copy link
Owner

jeroen commented Mar 18, 2015

After off-list discussion we decided to keep things the way they are.

When calling toJSON on a primitive with auto_unbox = TRUE, you get what you ask for which is simply the serialized primitive. The JSON.stringify function in JavaScript shows the same behavior. Although this is technically not valid JSON, it is valid JavaScript and can be used as such.

To ensure that the output is always valid JSON, simply wrap your object in I() which does exactly this: toJSON(I(pi), auto_unbox = TRUE).

@jeroen jeroen closed this as completed Mar 18, 2015
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

Successfully merging a pull request may close this issue.

2 participants