Struct polars::prelude::ArrowJsonReader [−]
pub struct ArrowJsonReader<R> where
R: Read, { /* fields omitted */ }
Expand description
JSON Reader
This JSON reader allows JSON line-delimited files to be read into the Arrow memory model. Records are loaded in batches and are then converted from row-based data to columnar data.
Example:
use std::sync::Arc;
use arrow2::datatypes::{DataType, Field, Schema};
use arrow2::io::json;
use std::io::{Cursor, BufReader};
let schema = Arc::new(Schema::new(vec![
Field::new("a", DataType::Int64, true),
Field::new("b", DataType::Float32, true),
Field::new("c", DataType::Boolean, true),
Field::new("d", DataType::Utf8, true),
]));
let data = r#"{"a":1, "b":2.0, "c":false, "d":"4"}
{"a":-10, "b":-3.5, "c":true, "d":null}
{"a":100000000, "b":0.6, "d":"text"}"#;
let mut reader = BufReader::new(Cursor::new(data));
let mut reader = json::Reader::new(&mut reader, schema, 1024, None);
let batch = reader.next().unwrap().unwrap();
Implementations
Create a new JSON Reader from any value that implements the Read
trait.
If reading a File
, you can customise the Reader, such as to enable schema
inference, use ReaderBuilder
.
Create a new JSON Reader from a BufReader<R: Read>
To customize the schema, such as to enable schema inference, use ReaderBuilder
Returns the schema of the reader, useful for getting the schema without reading record batches
pub fn next(&mut self) -> Result<Option<RecordBatch>, ArrowError>
pub fn next(&mut self) -> Result<Option<RecordBatch>, ArrowError>
Read the next batch of records