34 releases (major breaking)

new 53.3.0 Nov 20, 2024
53.0.0 Sep 3, 2024
52.2.0 Jul 28, 2024
51.0.0 Mar 18, 2024
27.0.0 Nov 14, 2022

#668 in Parser implementations

Download history 245616/week @ 2024-08-02 245903/week @ 2024-08-09 266855/week @ 2024-08-16 249818/week @ 2024-08-23 232091/week @ 2024-08-30 251365/week @ 2024-09-06 229002/week @ 2024-09-13 264790/week @ 2024-09-20 248915/week @ 2024-09-27 287102/week @ 2024-10-04 259046/week @ 2024-10-11 266306/week @ 2024-10-18 383342/week @ 2024-10-25 242196/week @ 2024-11-01 267847/week @ 2024-11-08 238011/week @ 2024-11-15

1,197,994 downloads per month
Used in 45 crates (13 directly)

Apache-2.0

3MB
58K SLoC

Transfer data between the Arrow memory format and JSON line-delimited records.

See the module level documentation for the reader and writer for usage examples.

Binary Data

As per RFC7159 JSON cannot encode arbitrary binary data. A common approach to workaround this is to use a binary-to-text encoding scheme, such as base64, to encode the input data and then decode it on output.

#
// The data we want to write
let input = BinaryArray::from(vec![b"\xDE\x00\xFF".as_ref()]);

// Base64 encode it to a string
let encoded: StringArray = b64_encode(&BASE64_STANDARD, &input);

// Write the StringArray to JSON
let batch = RecordBatch::try_from_iter([("col", Arc::new(encoded) as _)]).unwrap();
let mut buf = Vec::with_capacity(1024);
let mut writer = LineDelimitedWriter::new(&mut buf);
writer.write(&batch).unwrap();
writer.finish().unwrap();

// Read the JSON data
let cursor = Cursor::new(buf);
let mut reader = ReaderBuilder::new(batch.schema()).build(cursor).unwrap();
let batch = reader.next().unwrap().unwrap();

// Reverse the base64 encoding
let col: BinaryArray = batch.column(0).as_string::<i32>().clone().into();
let output = b64_decode(&BASE64_STANDARD, &col).unwrap();

assert_eq!(input, output);

Dependencies

~6–12MB
~139K SLoC