33 releases (major breaking)

53.2.0 Oct 24, 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

#671 in Parser implementations

Download history 241836/week @ 2024-07-23 255848/week @ 2024-07-30 236369/week @ 2024-08-06 256345/week @ 2024-08-13 260411/week @ 2024-08-20 228524/week @ 2024-08-27 259549/week @ 2024-09-03 246971/week @ 2024-09-10 230943/week @ 2024-09-17 262384/week @ 2024-09-24 257640/week @ 2024-10-01 276830/week @ 2024-10-08 261023/week @ 2024-10-15 341918/week @ 2024-10-22 293001/week @ 2024-10-29 267508/week @ 2024-11-05

1,204,453 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

~7–12MB
~140K SLoC