Serde_json: store struct in a Value

I'm working with a free-form JSON into which I'd like to store known structures. For example:

#[derive(Debug, Serialize)]
struct AnyData {
    value: serde_json::Value,
}

#[derive(Debug, Serialize)]
struct Person {
    name: String,
    address: String,
}

I'd like to populate AnyData::value with Person. Is there a way without serialising Person, deserialising it as Value and then serialising the entire AnyData as JSON?

This is a bit simplistic example but my restriction is that AnyData doesn't know/care what is going to end up in value.

How about to_value?

1 Like

Of course, thanks!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.