Expand description
(De)serialize JSON files.
Read JSON to a DataFrame
Example
use polars_core::prelude::*;
use polars_io::prelude::*;
use std::io::Cursor;
let basic_json = r#"{"a":1, "b":2.0, "c":false, "d":"4"}
{"a":-10, "b":-3.5, "c":true, "d":"4"}
{"a":2, "b":0.6, "c":false, "d":"text"}
{"a":1, "b":2.0, "c":false, "d":"4"}
{"a":7, "b":-3.5, "c":true, "d":"4"}
{"a":1, "b":0.6, "c":false, "d":"text"}
{"a":1, "b":2.0, "c":false, "d":"4"}
{"a":5, "b":-3.5, "c":true, "d":"4"}
{"a":1, "b":0.6, "c":false, "d":"text"}
{"a":1, "b":2.0, "c":false, "d":"4"}
{"a":1, "b":-3.5, "c":true, "d":"4"}
{"a":1, "b":0.6, "c":false, "d":"text"}"#;
let file = Cursor::new(basic_json);
let df = JsonReader::new(file)
.with_json_format(JsonFormat::JsonLines)
.infer_schema_len(Some(3))
.with_batch_size(3)
.finish()
.unwrap();
println!("{:?}", df);
Outputs:
+-----+--------+-------+--------+
| a | b | c | d |
| --- | --- | --- | --- |
| i64 | f64 | bool | str |
+=====+========+=======+========+
| 1 | 2 | false | "4" |
+-----+--------+-------+--------+
| -10 | -3.5e0 | true | "4" |
+-----+--------+-------+--------+
| 2 | 0.6 | false | "text" |
+-----+--------+-------+--------+
| 1 | 2 | false | "4" |
+-----+--------+-------+--------+
| 7 | -3.5e0 | true | "4" |
+-----+--------+-------+--------+
| 1 | 0.6 | false | "text" |
+-----+--------+-------+--------+
| 1 | 2 | false | "4" |
+-----+--------+-------+--------+
| 5 | -3.5e0 | true | "4" |
+-----+--------+-------+--------+
| 1 | 0.6 | false | "text" |
+-----+--------+-------+--------+
| 1 | 2 | false | "4" |
+-----+--------+-------+--------+
Modules
json
io_json
Convert data between the Arrow memory format and JSON line-delimited records.
ndjson
io_json
APIs to read from and write to NDJSON
Structs
Enums
Type Definitions
Typedef for a std::result::Result
of an ArrowError
.