set_nested_value

Function set_nested_value 

Source
pub fn set_nested_value(data: &mut Value, path: &str, value: Value)
Expand description

Set nested value in JSON using dot notation path

Creates intermediate objects or arrays as needed when navigating the path. Supports setting values in nested objects and arrays with automatic expansion.

§Path Syntax

  • "user.name" - Set object property
  • "items.0" - Set array element
  • "data.#20" - Set field named “20” (# prefix removed)
  • "data.##" - Set field named “#” (first # removed)

§Arguments

  • data - The JSON value to modify
  • path - Dot-separated path to the target location
  • value - The value to set at the target location

§Example

use serde_json::json;
use dataflow_rs::engine::utils::set_nested_value;

let mut data = json!({});
set_nested_value(&mut data, "user.name", json!("Alice"));
assert_eq!(data, json!({"user": {"name": "Alice"}}));