Your question is Manipulating Complex JSON. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Synechron frontend configuration tools receive deeply nested JSON payloads that must be edited without mutating the original input. Implement ordered JSON Pointer mutations for replacing existing values and deleting object properties or array elements.
Write apply_operations(document, operations), where document is a JSON-compatible Python value containing dictionaries, lists, strings, numbers, booleans, or None. Each operation is a dictionary with:
op: either "set" or "delete".path: a non-empty JSON Pointer string beginning with /. Object keys are separated by /, and ~1 represents / while ~0 represents ~.value: required only for "set".Every path is valid for the document state at the time its operation runs. A set replaces an existing object value or array element. A delete removes an object property or removes an array element, shifting later elements left. Operations must be applied in order. Return a deep-copied document and leave document unchanged.
/ and are valid JSON Pointer pathsdef apply_operations(document, operations):