
Flatten a JSON array
json_flatten(
x,
ptype = NULL,
allow_scalars = FALSE,
wrap_scalars = FALSE,
bigint_as_char = bigint_default()
)
A JSON vector.
Output type. If NULL
, the default, the output type is
determined by computing the common type across all elements. Use
new_json_array()
resp. new_json_object()
if you know every element is
an array resp. object. Mind that the return type will only be json2
.
Do not error for scalar elements?
Should scalar values be wrapped? Note that scalars are only wrapped if either
ptype
is new_json_array()
or json2
vector.
ptype
is NULL
and the elements are a mix of scalar values and arrays.
Convert big integers to character? The option
jsontools.bigint_as_char
is used as default.
A flattened version of x
with class given by ptype
and length
equal to the sum of the json_array_length()
of the components of x
.
# NOT RUN {
json_flatten(c("[1, 2]", "[3]"))
# names are kep
json_flatten(c(x = "[1, 2]", y = "[3]"))
# scalar elements produce an error ...
try(json_flatten(c(x = "[1, 2]", y = "3")))
# ... but can be explicitly allowed with `allow_scalars`
json_flatten(c(x = "[1, 2]", y = "3"), allow_scalars = TRUE)
# }
Run the code above in your browser using DataLab