37 releases (major breaking)

54.1.0 Feb 2, 2025
54.0.0 Dec 23, 2024
53.4.0 Jan 18, 2025
53.3.0 Nov 20, 2024
27.0.0 Nov 14, 2022

#203 in Parser implementations

Download history 341918/week @ 2024-10-22 293001/week @ 2024-10-29 267793/week @ 2024-11-05 247781/week @ 2024-11-12 237433/week @ 2024-11-19 137709/week @ 2024-11-26 194282/week @ 2024-12-03 246931/week @ 2024-12-10 197739/week @ 2024-12-17 83439/week @ 2024-12-24 152319/week @ 2024-12-31 264865/week @ 2025-01-07 258210/week @ 2025-01-14 238914/week @ 2025-01-21 236407/week @ 2025-01-28 212794/week @ 2025-02-04

1,000,635 downloads per month
Used in 49 crates (14 directly)

Apache-2.0

3MB
61K 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

~7–13MB
~141K SLoC