Skip to main content

set_property

Function set_property 

Source
pub fn set_property(object: &mut Value, path: &str, value: Value)
Expand description

Set value at path, creating intermediate objects/arrays as needed.

Numeric segments create arrays; string segments create objects. Existing non-container values along the path are replaced. No-op if object is not a container or path is empty/malformed.

let mut value = json!({});
set_property(&mut value, "a.b.0", json!("x"));
assert_eq!(value, json!({ "a": { "b": ["x"] } }));