Skip to main content

upsert_json_value

Function upsert_json_value 

Source
pub(crate) fn upsert_json_value(
    data: &mut Value,
    value: &str,
    key: &str,
) -> Result<()>
Expand description

Upserts a value into a JSON object based on an object-key path.

This function navigates through a mutable serde_json::Value object using a path-like key. It creates nested JSON objects if they do not exist along the path. The value is inserted at the final key in the path.

§Arguments

  • data - A mutable reference to the serde_json::Value to be modified.
  • value - The string representation of the value to upsert. This string is first parsed as JSON, and if that fails, it’s treated as a plain JSON string.
  • key - A path of dot-separated or bracket-quoted object keys.