[−][src]Module polars::frame::ser::json
(De)serialize JSON files.
Read JSON to a DataFrame
Example
use polars::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":100000000000000, "b":0.6, "c":false, "d":"text"}"#; let file = Cursor::new(basic_json); let df = JsonReader::new(file) .infer_schema(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" |
+-----+--------+-------+--------+
Structs
JsonReader | |
ReaderBuilder | JSON file reader builder |