Learn R Programming

jsonlite (version 1.8.8)

validate: Validate JSON

Description

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

Usage

validate(txt)

Arguments

txt

JSON string

Examples

Run this code
#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

Run the code above in your browser using DataLab