json_assert_valid: Assert vector is valid JSON.

View source: R/json.R

json_is_validR Documentation

Assert vector is valid JSON.

Description

Uses jsonlite::validate() under the hood.

Usage

json_is_valid(x)

json_assert_valid(x, x_arg = "", ..., error_call = caller_env())

Arguments

x

A character vector.

x_arg

Argument name for x. Used in error message to inform the user about the location of the error.

...

These dots are for future extensions and must be empty.

error_call

The execution environment of a currently running function, e.g. rlang::caller_env(). The function will be mentioned in error messages as the source of the error. See the call argument of rlang::abort() for more information.

Value

json_is_valid() returns a vector of TRUE and FALSE. json_assert_valid() either throws an error with information on the invalid elements or returns x invisibly

Examples

json_is_valid("[1, 2]")
json_is_valid("[1, 2")

json_assert_valid("[1, 2]")
## Not run: 
json_assert_valid("[1, 2")

## End(Not run)

mgirlich/jsontools documentation built on March 21, 2023, 9:10 a.m.