24 major breaking releases

51.0.0 Mar 18, 2024
50.0.0 Jan 12, 2024
49.0.0 Nov 13, 2023
48.0.1 Nov 13, 2023
27.0.0 Nov 14, 2022

#258 in Parser implementations

Download history 27242/week @ 2023-12-23 36996/week @ 2023-12-30 48496/week @ 2024-01-06 46952/week @ 2024-01-13 58886/week @ 2024-01-20 70800/week @ 2024-01-27 75197/week @ 2024-02-03 85773/week @ 2024-02-10 70250/week @ 2024-02-17 96582/week @ 2024-02-24 97084/week @ 2024-03-02 99850/week @ 2024-03-09 103163/week @ 2024-03-16 90009/week @ 2024-03-23 85338/week @ 2024-03-30 69741/week @ 2024-04-06

365,076 downloads per month
Used in 21 crates (8 directly)

Apache-2.0

2.5MB
50K 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–14MB
~134K SLoC