I'm trying to construct a JSON in rust using serde using structs.
{
"parent": { "database_id": "123" },
"properties": {
"title": {
"title": [
{
"text": {
"content": "Yurts in Big Sur, 123"
}
}
]
}
}
}
There's a lot of nested structures. Should I create a struct for each nest? In the case of the two "title" properties. How do I handle that?
I tried to create a struct for each nest.
Here's how it looks like
#[derive(Serialize)]
struct DBRow {
parent: Parent,
properties: Properties,
}
#[derive(Serialize)]
struct Parent {
database_id: String
}
#[derive(Serialize)]
struct Properties {
title: PropTitle
}
#[derive(Serialize)]
struct PropTitle {
title: Vec<Text>
}
#[derive(Serialize)]
struct Text {
content: String
}
#[derive(Deserialize)]
struct CreateUser {
username: String,
}