JSON Pointer (RFC 6901)
← run 2 · raw JSON · challenge definitions
—
score
tests (60%)—
deliverables (20%)—
content checks (20%)—
qwen3-30b-a3b: timed out
01 what the model was asked
Create jsonpointer.py with exactly one function:
resolve(doc, pointer: str)
Resolve an RFC 6901 JSON Pointer against doc (nested dicts/lists) and return the referenced value.
Rules:
- The empty pointer "" refers to the whole document.
- A pointer is a sequence of /-prefixed reference tokens: "/a/b" means doc["a"]["b"].
- In a token, the escape ~1 decodes to "/" and ~0 decodes to "~" (decode ~1 before ~0).
- Tokens indexing a list are decimal indices: "/items/0" is the first element.
- Raise KeyError for anything that does not resolve (missing key, bad or out-of-range index, pointer not starting with "/", descending into a scalar).
Use only the Python standard library.
required deliverables + checks
✓deliverable: jsonpointer.py
✓jsonpointer.py must contain “def resolve”
pytest suite it was graded against
test_jsonpointer.py · 56 lines · 996 B
import pytest from jsonpointer import resolve DOC = { "foo": ["bar", "baz"], "": 0, "a/b": 1, "m~n": 8, "nested": {"list": [{"x": 42}]},} def test_whole_document(): assert resolve(DOC, "") is DOC def test_object_key(): assert resolve(DOC, "/foo") == ["bar", "baz"] def test_array_index(): assert resolve(DOC, "/foo/0") == "bar" def test_empty_key(): assert resolve(DOC, "/") == 0 def test_escaped_slash(): assert resolve(DOC, "/a~1b") == 1 def test_escaped_tilde(): assert resolve(DOC, "/m~0n") == 8 def test_deep_path(): assert resolve(DOC, "/nested/list/0/x") == 42 def test_missing_key_raises(): with pytest.raises(KeyError): resolve(DOC, "/nope") def test_bad_index_raises(): with pytest.raises(KeyError): resolve(DOC, "/foo/2") with pytest.raises(KeyError): resolve(DOC, "/foo/x") def test_pointer_without_slash_raises(): with pytest.raises(KeyError): resolve(DOC, "foo")
02 what it did — full transcript
write_fileturn 1 · jsonpointer.py · 804 B
run_teststurn 2 ·
✗ 1 failing9 passed
! errorqwen3-30b-a3b: timed out
03 what it wrote
1
files
26
lines
26
source lines
1
functions
0
classes
11
cyclomatic
6
max nesting
26.0
avg fn lines
stdlib imports: none
| File | LOC | SLOC | Fns | Complexity | Depth | Imports |
|---|---|---|---|---|---|---|
| jsonpointer.py | 26 | 26 | 1 | 11 | 6 | — |
jsonpointer.py · 26 lines · 804 B
def resolve(doc, pointer): if pointer == '': return doc if not pointer.startswith('/'): raise KeyError tokens = pointer.split('/')[1:] current = doc for token in tokens: token = token.replace('~1', '/').replace('~0', '~') if token == '': raise KeyError if isinstance(current, dict): if token not in current: raise KeyError current = current[token] elif isinstance(current, list): try: index = int(token) if index < 0 or index >= len(current): raise KeyError current = current[index] except ValueError: raise KeyError else: raise KeyError return current
04 how it was graded
2
model calls
0
invalid actions
1
self test runs
10.3k
tokens out
—
tokens in
1399.9s
wall time
agent actions: write_file×1, run_tests×1