I have JSON where a key has an array of objects and I'm only interested in one of the strings within that:
{
"actors": [{
"name": "Bob",
"foo": "bar"
}, {
"name": "Jim",
"foo": "baz"
}],
"fruits": [{
"name": "Pineapple",
"foo": "bar"
}, {
"name": "Apple",
"foo": "baz"
}]
}
I have
use serde::Deserialize; // 1.0.110
#[derive(Deserialize)]
pub struct Name {
pub name: String,
}
#[derive(Deserialize)]
pub struct Data {
pub actors: Vec<Name>,
pub fruits: Vec<Name>,
}
How can I flatten that so I can have Vec<String>
rather than Vec<Name>
? e.g. I want to end up with
actors: ["Bob", "Jim"],
fruits: ["Pineapple", "Apple"],