2 unstable releases

0.13.0 Oct 26, 2023
0.11.3 Oct 10, 2023
0.10.1 Jun 26, 2023
0.7.0 Nov 3, 2022
0.1.9 Jul 10, 2020

#1708 in Encoding

Download history 939/week @ 2024-03-14 330/week @ 2024-03-21 620/week @ 2024-03-28 968/week @ 2024-04-04 589/week @ 2024-04-11 607/week @ 2024-04-18 356/week @ 2024-04-25 359/week @ 2024-05-02 518/week @ 2024-05-09 534/week @ 2024-05-16 507/week @ 2024-05-23 565/week @ 2024-05-30 422/week @ 2024-06-06 658/week @ 2024-06-13 490/week @ 2024-06-20 174/week @ 2024-06-27

1,785 downloads per month
Used in 8 crates (6 directly)

Apache-2.0/MIT

49KB
1.5K SLoC

simd-json-derive

Latest version documentation License

Derives for high performance JSON serialisation and deserialisation.

Usage


#[derive(Serialize, Deserialize, Debug)]
#[simd_json(deny_unknown_fields, rename_all = "camelCase")]
struct MyStruct {
    first_field: String,
    #[simd_json(rename = "foo")]
    second_field: Option<usize>
}

fn main -> Result<(), simd_json::Error> {
    let my_struct = MyStruct {
        first_field: "i am first".to_string(),
        second_field: None
    }
    println!("Before: {my_struct:?}");
    let mut json_string = my_struct.json_string()?;
    let deserialized = MyStruct::from_str(json_string.as_mut_str())?;
    println!("After: {deserialized:?}");
}

Supported Attributes

Attributres are supported for both #[simd_json(...)] and for compatibilty also for #[serde(...)] and follow the same naming conventions as serde.

For fields:

  • rename = "new_name" - renames a field

For structs:

  • rename_all = "camelCase" - renames all (not otherwise renamed) based on the rule, camelCase is currently supported
  • deny_unknown_fields - Errors if unknown fields are encountered

Dependencies

~6MB
~105K SLoC