Skip to content

Write to JSON file

Description

Write to JSON file

Usage

<DataFrame>$write_json(file, ..., pretty = FALSE, row_oriented = FALSE)

Arguments

file File path to which the result should be written.
Ignored.
pretty Pretty serialize JSON.
row_oriented Write to row-oriented JSON. This is slower, but more common.

Value

Invisibly returns the input DataFrame.

Examples

library(polars)

if (require("jsonlite", quiet = TRUE)) {
  dat = pl$DataFrame(head(mtcars))
  destination = tempfile()

  dat$select(pl$col("drat", "mpg"))$write_json(destination)
  jsonlite::fromJSON(destination)

  dat$select(pl$col("drat", "mpg"))$write_json(destination, row_oriented = TRUE)
  jsonlite::fromJSON(destination)
}
#>   drat  mpg
#> 1 3.90 21.0
#> 2 3.90 21.0
#> 3 3.85 22.8
#> 4 3.08 21.4
#> 5 3.15 18.7
#> 6 2.76 18.1