serde manipulate json (change, add)



examples/json/serde-manipulate-json/Cargo.toml
[package]
name = "serde-demo"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.97"

examples/json/serde-manipulate-json/src/main.rs
use serde_json::json;

fn main() {
    let mut object = json!({ "A": 1, "B": 2, "C": 3 });
    dbg!(&object);

    *object.get_mut("A").unwrap() = json!(100);
    dbg!(&object);

    object["D"] = json!(200);
    dbg!(&object);

    object["E"] = json!("text");
    dbg!(&object);

    object["F"] = json!(vec!["apple", "banana"]);
    dbg!(&object);
}