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

#259 in Parser implementations

Download history 54033/week @ 2024-01-18 66382/week @ 2024-01-25 76031/week @ 2024-02-01 70648/week @ 2024-02-08 80310/week @ 2024-02-15 93085/week @ 2024-02-22 99935/week @ 2024-02-29 95494/week @ 2024-03-07 104341/week @ 2024-03-14 91114/week @ 2024-03-21 89655/week @ 2024-03-28 81942/week @ 2024-04-04 93300/week @ 2024-04-11 135634/week @ 2024-04-18 130516/week @ 2024-04-25 100691/week @ 2024-05-02

475,303 downloads per month
Used in 23 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–13MB
~134K SLoC