PPointerMallow
Workflows

Coding workflows · JSON Pointer navigation

03
Built around your work

A concrete starting point

Resolve a JSON Pointer against dictionaries and lists without editing them. Test the empty root pointer and escaped keys, rejecting malformed escapes, missing members and noncanonical array indices.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

JSON Pointer navigation

A concrete starting point
import re
def pointer_get(root, pointer):
    if not isinstance(pointer, str): raise ValueError("pointer text")
    if pointer == "": return root
    if not pointer.startswith("/"): raise ValueError("root slash")
    value = root
    for raw in pointer[1:].split("/"):
        if re.search(r"~(?![01])", raw): raise ValueError("escape")
        key = raw.replace("~1", "/").replace("~0", "~")
        if isinstance(value, dict): value = value[key]
        elif isinstance(value, list):
            if not re.fullmatch(r"0|[1-9][0-9]*", key):
                raise ValueError("array index")
            if len(key) > len(str(len(value))): raise IndexError(key)
            value = value[int(key)]
        else: raise ValueError("not a container")
    return value

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗