90 releases

0.0.117 Apr 20, 2024
0.0.108 Mar 30, 2024
0.0.94 Dec 12, 2023
0.0.91 Nov 13, 2023
0.0.37 May 27, 2022

#2105 in Encoding

Download history 370/week @ 2024-02-14 17/week @ 2024-02-21 128/week @ 2024-02-28 29/week @ 2024-03-06 68/week @ 2024-03-13 969/week @ 2024-03-20 475/week @ 2024-03-27 366/week @ 2024-04-03 494/week @ 2024-04-10 483/week @ 2024-04-17 15/week @ 2024-04-24 2/week @ 2024-05-01

1,190 downloads per month
Used in 2 crates

MIT/Apache

1MB
27K SLoC

musli-json

github crates.io docs.rs build status

JSON support for Müsli suitable for network and usually browser communication.

JSON encoding is fully upgrade stable:

  • ✔ Can tolerate missing fields if they are annotated with #[musli(default)].
  • ✔ Can skip over unknown fields.
use musli::{Encode, Decode};

#[derive(Debug, PartialEq, Encode, Decode)]
struct Version1 {
    name: String,
}

#[derive(Debug, PartialEq, Encode, Decode)]
struct Version2 {
    name: String,
    #[musli(default)]
    age: Option<u32>,
}

let version2 = musli_json::to_vec(&Version2 {
    name: String::from("Aristotle"),
    age: Some(62),
})?;

let version1: Version1 = musli_json::from_slice(version2.as_slice())?;

assert_eq!(version1, Version1 {
    name: String::from("Aristotle"),
});

Dependencies

~1.7–2.3MB
~44K SLoC