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.
Path to file containing NDJSON data. May e a vanilla text file or a gzipped file
The type of R object the JSON should be parsed into. Valid values are 'df' or 'list'. Default: 'df' (data.frame)
Number of records to read. Default: -1 (reads all JSON strings)
Number of records to skip before starting to read. Default: 0 (skip no data)
Number of lines to read to determine types for data.frame
columns. Default: 100. Use -1
to probe entire file.
Named list of options for parsing. Usually created by opts_read_json()
Other named options can be used to override any options in opts
.
The valid named options are identical to arguments to opts_read_json()
NDJSON data read into R as list or data.frame depending
on 'type'
argument
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.
Other JSON Parsers:
read_json_conn()
,
read_json_file()
,
read_json_raw()
,
read_json_str()
,
read_ndjson_str()
tmp <- tempfile()
write_ndjson_file(head(mtcars), tmp)
read_ndjson_file(tmp)
#> mpg cyl disp hp drat wt qsec vs am gear carb
#> 1 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
#> 2 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
#> 3 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
#> 4 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
#> 5 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
#> 6 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1