json_merge_patch

Function json_merge_patch 

Source
pub fn json_merge_patch(target: &Value, patch: &Value) -> Value
Expand description

Apply a JSON Merge Patch (RFC 7396) to a document.

§Arguments

  • target - The original JSON document
  • patch - The merge patch to apply

§Returns

A new JSON document with the patch applied.

§Rules

  • If patch is not an object, it replaces target entirely
  • If patch is an object:
    • For each key in patch:
      • If value is null, remove the key from target
      • If value is an object and target has an object at that key, merge recursively
      • Otherwise, set the key to the patch value