#Failed to deserialize json data into struct since `type` is a keyword

4 messages · Page 1 of 1 (latest)

agile path
#
#[derive(serde::Deserialize)]
struct ChildrenEntry {
    date_added: String,
    date_last_used: String,
    guid: String,
    id: String,
    meta_info: BookmarkIgnore3,
    name: String,
    type: String,
    url: String,
}

I am trying to deserialize into this type ChildrenEntry but type is a keyword

coarse halo
timber tide
#

or (worse) r#type for the field's name

dusk thorn
# agile path ```rs #[derive(serde::Deserialize)] struct ChildrenEntry { date_added: Strin...

As Helix (noop_noob) suggested I would suggest using serde rename to rename the field automatically during deserialization because otherwise the word type is a reserved keyword in rust and you cannot use it. So according to the suggestion here is the updated version of your code 🙂 :

#[derive(serde::Deserialize)]
struct ChildrenEntry {
    date_added: String,
    date_last_used: String,
    guid: String,
    id: String,
    meta_info: BookmarkIgnore3,
    name: String,
    #[serde(rename = "type")]
    some_type: String,
    url: String,
}

I hope this helps 🙂