I am trying to deserialize JSON data that looks like the following using serde:
{
"item1": "Foo",
"item2": "Bar",
"item3": "Baz",
"item4": null,
"item5": null,
"description1": "something",
"description2": "another thing",
"description3": "one more thing",
"description4": null,
"description5": null
}
It can be assumed that there are only 5 items and the fields will always be present (but possibly null).
I was hoping to place it into a Vec<Item>
where
struct Item {
name: String,
description: String,
}
I am aware that I can #[derive(Deserialize)]
and alias the name field, but I'm not sure how to handle transforming the numbered items into a list. How would one go about handling a case like this in serde?