parse_json: Convert JSON to an R object

Description Usage Arguments Details Value Examples

View source: R/read_json.R

Description

A wrapper around the great jsonlite::parse_json. The differences are:

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
parse_json(
  x,
  .na = json_na_error(),
  .null = NULL,
  simplifyVector = TRUE,
  simplifyDataFrame = FALSE,
  simplifyMatrix = FALSE,
  flatten = FALSE,
  bigint_as_char = bigint_default(),
  ...
)

Arguments

x

a scalar JSON character

.na

Value to return if x is NA. By default an error of class jsontools_error_na_json is thrown.

.null

Return the prototype of .null if x is NULL or a zero length character

simplifyVector, simplifyDataFrame, simplifyMatrix, flatten, ...

passed on to jsonlite::parse_json.

bigint_as_char

Parse big integers as character? The option jsontools.bigint_as_char is used as default.

Details

To parse a vector of JSON use parse_json_vector.

Value

A R object. The type depends on the input but is usually a list or a data frame.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# Parse escaped unicode
parse_json('{"city" : "Z\\u00FCrich"}')

# big integers
big_num <- "9007199254740993"
as.character(parse_json(big_num, bigint_as_char = FALSE))
as.character(parse_json(big_num, bigint_as_char = TRUE))

# NA error by default
try(parse_json(NA))
# ... but one can specify a default value
parse_json(NA, .na = data.frame(a = 1, b = 2))

# input of size 0
parse_json(NULL)
parse_json(character(), .null = data.frame(a = 1, b = 2))

jsontools documentation built on March 22, 2021, 5:06 p.m.