35 releases (major breaking)

54.0.0 Dec 23, 2024
53.3.0 Nov 20, 2024
53.2.0 Oct 24, 2024
52.2.0 Jul 28, 2024
27.0.0 Nov 14, 2022

#367 in Parser implementations

Download history 250308/week @ 2024-09-26 279851/week @ 2024-10-03 262382/week @ 2024-10-10 252094/week @ 2024-10-17 391208/week @ 2024-10-24 242359/week @ 2024-10-31 272039/week @ 2024-11-07 241883/week @ 2024-11-14 215038/week @ 2024-11-21 136866/week @ 2024-11-28 226048/week @ 2024-12-05 233335/week @ 2024-12-12 128830/week @ 2024-12-19 85036/week @ 2024-12-26 224734/week @ 2025-01-02 238034/week @ 2025-01-09

721,292 downloads per month
Used in 46 crates (12 directly)

Apache-2.0

3MB
59K 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
~140K SLoC