32 releases (8 breaking)

0.10.1 Jun 26, 2023
0.9.2 May 4, 2023
0.7.0 Nov 3, 2022
0.4.0 Jul 8, 2022
0.1.9 Jul 10, 2020

#202 in Parser implementations

Download history 199/week @ 2023-05-31 86/week @ 2023-06-07 159/week @ 2023-06-14 324/week @ 2023-06-21 361/week @ 2023-06-28 608/week @ 2023-07-05 535/week @ 2023-07-12 217/week @ 2023-07-19 135/week @ 2023-07-26 96/week @ 2023-08-02 124/week @ 2023-08-09 265/week @ 2023-08-16 584/week @ 2023-08-23 90/week @ 2023-08-30 157/week @ 2023-09-06 159/week @ 2023-09-13

1,065 downloads per month
Used in 5 crates (4 directly)

Apache-2.0/MIT

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

~4.5MB
~90K SLoC