MCPcopy Create free account
hub / github.com/calfonso/rusternetes / apply_json_patch

Function apply_json_patch

crates/api-server/src/patch.rs:148–159  ·  view source on GitHub ↗

Apply JSON Patch (RFC 6902)

(original: &Value, patch: &Value)

Source from the content-addressed store, hash-verified

146
147/// Apply JSON Patch (RFC 6902)
148fn apply_json_patch(original: &Value, patch: &Value) -> Result<Value, PatchError> {
149 let operations: Vec<JsonPatchOperation> = serde_json::from_value(patch.clone())
150 .map_err(|e| PatchError::InvalidPatch(e.to_string()))?;
151
152 let mut current = original.clone();
153
154 for op in operations {
155 current = apply_json_patch_operation(&current, &op)?;
156 }
157
158 Ok(current)
159}
160
161/// Apply a single JSON Patch operation
162fn apply_json_patch_operation(value: &Value, op: &JsonPatchOperation) -> Result<Value, PatchError> {

Callers 4

apply_patchFunction · 0.70
test_json_patch_addFunction · 0.70
test_json_patch_removeFunction · 0.70
test_json_patch_replaceFunction · 0.70

Calls 1

Tested by 3

test_json_patch_addFunction · 0.56
test_json_patch_removeFunction · 0.56
test_json_patch_replaceFunction · 0.56