#How do I modify Json files the correct way with serde_json?

1 messages · Page 1 of 1 (latest)

quiet basin
#

“Completely overwrites the entire file” is the normal way that modifying any kind of text-like file (such as JSON) works.

#

You need to read the entire file, then write a replacement.

#

And you'll need a structure like

#[derive(Deserialize, Serialize)]
struct Container {
    person: Vec<Person>,
}

to match the outer part of the JSON

#

(And there shouldn't be any serde_json::Value involved — it doesn't help here.)