pub fn remove_nested_value(
data: &mut OwnedDataValue,
path: &str,
) -> Option<OwnedDataValue>Expand description
Remove the value at path and return it; None if the path does not resolve.
Completes the module’s read/write pair with a removal. Note that
set_nested_value(path, OwnedDataValue::Null) is not removal — it leaves an
explicit null in the tree, which survives every serialization boundary
because Message’s Serialize emits context whole.
Path syntax is identical to get_nested_value and set_nested_value:
dot-separated segments, numeric segments index arrays, and one leading # is
stripped from an object-key segment ("data.#20" is the object key "20").
- Object keys are removed from the pair vec; the relative order of the surviving pairs is preserved.
- Array elements are removed with a tail shift, so later indices move down.
- Returns
None— leavingdatauntouched — for a missing key, an out-of-bounds or non-numeric array index, an attempt to descend through a non-container, or an emptypath. Never panics.
Note the deliberate asymmetry with the read side: get_nested_value(d, "")
returns the whole tree, but there is no such thing as removing the root, so an
empty path yields None rather than taking data apart.
use dataflow_rs::datavalue::OwnedDataValue;
use dataflow_rs::engine::utils::remove_nested_value;
use serde_json::json;
let mut ctx = OwnedDataValue::from(&json!({"data": {"order_id": 7, "_scratch": 42}}));
let taken = remove_nested_value(&mut ctx, "data._scratch");
assert_eq!(taken, Some(OwnedDataValue::from(&json!(42))));
assert_eq!(
serde_json::Value::from(&ctx),
json!({"data": {"order_id": 7}}),
);