4 releases (breaking)

new 0.15.0 Oct 24, 2024
0.13.0 Oct 26, 2023
0.10.1 Jun 26, 2023
0.7.0 Nov 3, 2022
0.1.9 Jul 10, 2020

#1801 in Encoding

Download history 281/week @ 2024-07-07 131/week @ 2024-07-14 331/week @ 2024-07-21 135/week @ 2024-07-28 56/week @ 2024-08-04 153/week @ 2024-08-11 39/week @ 2024-08-18 94/week @ 2024-08-25 112/week @ 2024-09-01 40/week @ 2024-09-08 68/week @ 2024-09-15 296/week @ 2024-09-22 389/week @ 2024-09-29 96/week @ 2024-10-06 264/week @ 2024-10-13 378/week @ 2024-10-20

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

Apache-2.0/MIT

51KB
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

Attributes 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

~3–4.5MB
~82K SLoC