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

validate error messages appear later as attributes in parsed JSON #49

Closed
jeremystan opened this issue Oct 31, 2014 · 4 comments
Closed

Comments

@jeremystan
Copy link

When using jsonlite::validate on an invalid json character string, the resulting error message can appear later in the parsed JSON for valid false JSON data.

For example, when running this code:

library(jsonlite)
sessionInfo()
fromJSON('false') # This works just fine
validate('')      # Validate that '' is not valid JSON
fromJSON('false') # This now picks up the error message from validate('')
fromJSON('true')  # But this is fine

The output produced is:

> library(jsonlite)

Attaching package: ‘jsonlite’

The following object is masked from ‘package:utils’:

    View

Warning message:
package ‘jsonlite’ was built under R version 3.1.2
> sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-apple-darwin13.1.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] jsonlite_0.9.13
> fromJSON('false') # This works just fine
[1] FALSE
> validate('')      # Validate that '' is not valid JSON
[1] FALSE
attr(,"err")
[1] "parse error: premature EOF\n                                       \n                     (right here) ------^\n"
> fromJSON('false') # This now picks up the error message from validate('')
[1] FALSE
attr(,"err")
[1] "parse error: premature EOF\n                                       \n                     (right here) ------^\n"
> fromJSON('true')  # But this is fine
[1] TRUE
>
@jeroen
Copy link
Owner

jeroen commented Oct 31, 2014

Thank you, confirmed.

@jeroen
Copy link
Owner

jeroen commented Oct 31, 2014

I pushed a fix at 0e929a5. Could you test if this completely solves the problem?

@jeroen
Copy link
Owner

jeroen commented Oct 31, 2014

FYI this was the problem: https://stat.ethz.ch/pipermail/r-devel/2014-October/070010.html

@jeremystan
Copy link
Author

Confirmed, that commit resolved the specific issue above, and all tidyjson tests pass with validation turned back on.

@jeroen jeroen closed this as completed Nov 7, 2014
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

2 participants