42 stable releases (27 major)

new 54.3.1 Mar 30, 2025
54.2.1 Feb 27, 2025
54.0.0 Dec 23, 2024
53.4.1 Mar 7, 2025
27.0.0 Nov 14, 2022

#579 in Encoding

Download history 257402/week @ 2024-12-08 218119/week @ 2024-12-15 84539/week @ 2024-12-22 131153/week @ 2024-12-29 246407/week @ 2025-01-05 284694/week @ 2025-01-12 221069/week @ 2025-01-19 243376/week @ 2025-01-26 253006/week @ 2025-02-02 346218/week @ 2025-02-09 349753/week @ 2025-02-16 500636/week @ 2025-02-23 511975/week @ 2025-03-02 491134/week @ 2025-03-09 453631/week @ 2025-03-16 437193/week @ 2025-03-23

1,929,984 downloads per month
Used in 51 crates (17 directly)

Apache-2.0

3MB
64K 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
~144K SLoC