A SMALL PYTHON LIBRARY FOR UNFINISHED DATA

The response stopped.
Your JSON doesn’t
have to.

Close the brackets. Finish the string. Turn a truncated JSON document into something you can parse—with one function.

pip install untruncate_json

Python 3.9–3.15 · MIT licensed · No runtime dependencies

an interrupted response

01 / RECEIVED

{"items": [1, 2,

Connection ended. Document unfinished.

complete(partial)

02 / REPAIRED

{"items": [1, 2]}

Ready for json.loads()

One function.Typed Python API.Native mypyc wheels.Linux · macOS · Windows.

SMALL API, USEFUL REPAIRS

From almost JSON
to a Python value.

Pass in a complete document or a prefix of one. Get a string back. Use Python’s standard JSON parser for the next step.

Explore the API →
repair.py
import json
from untruncate_json import complete

partial = '{"items": [1, 2,'
repaired = complete(partial)

# {"items": [1, 2]}
data = json.loads(repaired)

Pick up where the document left off.

What got cut offInputRepaired output
A string"Hello, wor"Hello, wor"
A literal[true, fa[true, false]
A number123.123.0
An object value{"a": 1, "b":{"a": 1}

KNOW WHAT YOU’RE GETTING

Repair the structure.
Review the meaning.

Untruncate repairs a document that ends too soon. It cannot recover missing values or fix every kind of malformed JSON. Unfinished keys, trailing commas, and incomplete string escapes may be discarded.

Valid, complete JSON stays unchanged. Empty input stays empty. Always validate repaired data before relying on it.

Read the behavior and limits →

Works in your pipeline, too.

Read from stdin. Write the repaired JSON to stdout.

python -m untruncate_json < partial.json