How to use serde Value for dynamic JSON

Use serde_json::Value to parse and handle JSON with unknown or dynamic structures at runtime.

Use serde_json::Value to parse JSON into a dynamic, untyped structure that you can inspect at runtime without defining a struct. This is ideal when the JSON schema is unknown or varies between requests.

use serde_json::Value;

let json_str = r#"{"name": "Alice", "age": 30, "active": true}"#;
let value: Value = serde_json::from_str(json_str)?;

if let Value::Object(map) = value {
    if let Some(name) = map.get("name") {
        println!("Name: {}", name.as_str().unwrap());
    }
}