read_ndjson_str {yyjsonr} | R Documentation |
Parse an NDJSON file to a data.frame or list
Description
If reading as data.frame, each row of NDJSON becomes a row in the data.frame. If reading as a list, then each row becomes an element in the list.
Usage
read_ndjson_str(
x,
type = c("df", "list"),
nread = -1,
nskip = 0,
nprobe = 100,
opts = list(),
...
)
Arguments
x |
string containing NDJSON |
type |
The type of R object the JSON should be parsed into. Valid values are 'df' or 'list'. Default: 'df' (data.frame) |
nread |
Number of records to read. Default: -1 (reads all JSON strings) |
nskip |
Number of records to skip before starting to read. Default: 0 (skip no data) |
nprobe |
Number of lines to read to determine types for data.frame
columns. Default: 100. Use |
opts |
Named list of options for parsing. Usually created by |
... |
Other named options can be used to override any options in |
Details
If parsing NDJSON to a data.frame it is usually better if the json objects
are consistent from line-to-line. Type inference for the data.frame is done
during initialisation by reading through nprobe
lines. Warning: if
there is a type-mismatch further into the file than it is probed, then you
will get missing values in the data.frame, or JSON values not captured in
the R data.
No flattening of the namespace is done i.e. nested object remain nested.
Value
NDJSON data read into R as list or data.frame depending
on 'type'
argument
See Also
Other JSON Parsers:
read_json_conn()
,
read_json_file()
,
read_json_raw()
,
read_json_str()
,
read_ndjson_file()
Examples
tmp <- tempfile()
json <- write_ndjson_str(head(mtcars))
read_ndjson_str(json, type = 'list')