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.
string containing NDJSON
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_file()
tmp <- tempfile()
json <- write_ndjson_str(head(mtcars))
read_ndjson_str(json, type = 'list')
#> [[1]]
#> [[1]]$mpg
#> [1] 21
#>
#> [[1]]$cyl
#> [1] 6
#>
#> [[1]]$disp
#> [1] 160
#>
#> [[1]]$hp
#> [1] 110
#>
#> [[1]]$drat
#> [1] 3.9
#>
#> [[1]]$wt
#> [1] 2.62
#>
#> [[1]]$qsec
#> [1] 16.46
#>
#> [[1]]$vs
#> [1] 0
#>
#> [[1]]$am
#> [1] 1
#>
#> [[1]]$gear
#> [1] 4
#>
#> [[1]]$carb
#> [1] 4
#>
#>
#> [[2]]
#> [[2]]$mpg
#> [1] 21
#>
#> [[2]]$cyl
#> [1] 6
#>
#> [[2]]$disp
#> [1] 160
#>
#> [[2]]$hp
#> [1] 110
#>
#> [[2]]$drat
#> [1] 3.9
#>
#> [[2]]$wt
#> [1] 2.875
#>
#> [[2]]$qsec
#> [1] 17.02
#>
#> [[2]]$vs
#> [1] 0
#>
#> [[2]]$am
#> [1] 1
#>
#> [[2]]$gear
#> [1] 4
#>
#> [[2]]$carb
#> [1] 4
#>
#>
#> [[3]]
#> [[3]]$mpg
#> [1] 22.8
#>
#> [[3]]$cyl
#> [1] 4
#>
#> [[3]]$disp
#> [1] 108
#>
#> [[3]]$hp
#> [1] 93
#>
#> [[3]]$drat
#> [1] 3.85
#>
#> [[3]]$wt
#> [1] 2.32
#>
#> [[3]]$qsec
#> [1] 18.61
#>
#> [[3]]$vs
#> [1] 1
#>
#> [[3]]$am
#> [1] 1
#>
#> [[3]]$gear
#> [1] 4
#>
#> [[3]]$carb
#> [1] 1
#>
#>
#> [[4]]
#> [[4]]$mpg
#> [1] 21.4
#>
#> [[4]]$cyl
#> [1] 6
#>
#> [[4]]$disp
#> [1] 258
#>
#> [[4]]$hp
#> [1] 110
#>
#> [[4]]$drat
#> [1] 3.08
#>
#> [[4]]$wt
#> [1] 3.215
#>
#> [[4]]$qsec
#> [1] 19.44
#>
#> [[4]]$vs
#> [1] 1
#>
#> [[4]]$am
#> [1] 0
#>
#> [[4]]$gear
#> [1] 3
#>
#> [[4]]$carb
#> [1] 1
#>
#>
#> [[5]]
#> [[5]]$mpg
#> [1] 18.7
#>
#> [[5]]$cyl
#> [1] 8
#>
#> [[5]]$disp
#> [1] 360
#>
#> [[5]]$hp
#> [1] 175
#>
#> [[5]]$drat
#> [1] 3.15
#>
#> [[5]]$wt
#> [1] 3.44
#>
#> [[5]]$qsec
#> [1] 17.02
#>
#> [[5]]$vs
#> [1] 0
#>
#> [[5]]$am
#> [1] 0
#>
#> [[5]]$gear
#> [1] 3
#>
#> [[5]]$carb
#> [1] 2
#>
#>
#> [[6]]
#> [[6]]$mpg
#> [1] 18.1
#>
#> [[6]]$cyl
#> [1] 6
#>
#> [[6]]$disp
#> [1] 225
#>
#> [[6]]$hp
#> [1] 105
#>
#> [[6]]$drat
#> [1] 2.76
#>
#> [[6]]$wt
#> [1] 3.46
#>
#> [[6]]$qsec
#> [1] 20.22
#>
#> [[6]]$vs
#> [1] 1
#>
#> [[6]]$am
#> [1] 0
#>
#> [[6]]$gear
#> [1] 3
#>
#> [[6]]$carb
#> [1] 1
#>
#>