validate: Validate JSON

Description Usage Arguments Examples

View source: R/validate.R

Description

Test if a string contains valid JSON. Characters vectors will be collapsed into a single string.

Usage

1
validate(txt)

Arguments

txt

JSON string

Examples

1
2
3
4
5
6
7
#Output from toJSON and serializeJSON should pass validation
myjson <- toJSON(mtcars)
validate(myjson) #TRUE

#Something bad happened
truncated <- substring(myjson, 1, 100)
validate(truncated) #FALSE

Example output

[1] TRUE
[1] FALSE
attr(,"offset")
[1] 1
attr(,"err")
[1] "parse error: premature EOF\n                                       [{\"mpg\":21,\"cyl\":6,\"disp\":160,\"\n                     (right here) ------^\n"

jsonlite documentation built on Dec. 15, 2020, 5:24 p.m.