4 releases (breaking)

0.4.0 Oct 31, 2022
0.3.0 Oct 30, 2022
0.2.0 Oct 29, 2022
0.1.0 Oct 28, 2022

#316 in Encoding

Download history 153/week @ 2022-11-27 171/week @ 2022-12-04 455/week @ 2022-12-11 221/week @ 2022-12-18 89/week @ 2022-12-25 89/week @ 2023-01-01 149/week @ 2023-01-08 154/week @ 2023-01-15 286/week @ 2023-01-22 349/week @ 2023-01-29 260/week @ 2023-02-05 339/week @ 2023-02-12 340/week @ 2023-02-19 197/week @ 2023-02-26 225/week @ 2023-03-05 121/week @ 2023-03-12

898 downloads per month
Used in varfish-server-worker

MIT license

364 lines

Project Status: Active – The project has reached a stable, usable state and is being actively developed. CI Status codecov.io MIT License

GitHub | crates.io | Documentation | Issues | Changelog

JSON Lines (a.k.a. newline-delimited JSON) is a simple format for storing sequences of JSON values in which each value is serialized on a single line and terminated by a newline sequence. The serde-jsonlines crate provides functionality for reading & writing these documents (whether all at once or line by line) using serde's serialization & deserialization features.

Basic usage involves simply importing the BufReadExt or WriteExt extension trait and then using the json_lines() or write_json_lines() method on a BufRead or Write value to read or write a sequence of JSON Lines values. Convenience functions are also provided for the common case of reading or writing a JSON Lines file given as a filepath.

At a lower level, values can be read or written one at a time (which is useful if, say, different lines are different types) by wrapping a BufRead or Write value in a JsonLinesReader or JsonLinesWriter and then calling the wrapped structure's read() or write() method, respectively.

When the async feature is enabled, analogous types for working with JSON Lines asynchronously under tokio become available.


serde-jsonlines requires version 1.56 of Rust or higher. To use the serde-jsonlines library in your Cargo project, add the following to your Cargo.toml:

serde-jsonlines = "0.4.0"


use serde::{Deserialize, Serialize};
use serde_jsonlines::{json_lines, write_json_lines};
use std::io::Result;

#[derive(Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct Structure {
    pub name: String,
    pub size: i32,
    pub on: bool,

fn main() -> Result<()> {
    let values = vec![
        Structure {
            name: "Foo Bar".into(),
            size: 42,
            on: true,
        Structure {
            name: "Quux".into(),
            size: 23,
            on: false,
        Structure {
            name: "Gnusto Cleesh".into(),
            size: 17,
            on: true,
    write_json_lines("example.jsonl", &values)?;
    let values2 = json_lines("example.jsonl")?.collect::<Result<Vec<Structure>>>()?;
    assert_eq!(values, values2);


~82K SLoC