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_jsonPython 3.9–3.15 · MIT licensed · No runtime dependencies
01 / RECEIVED
{"items": [1, 2,Connection ended. Document unfinished.
02 / REPAIRED
{"items": [1, 2]}Ready for json.loads()
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 →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 off | Input | Repaired output |
|---|---|---|
| A string | "Hello, wor | "Hello, wor" |
| A literal | [true, fa | [true, false] |
| A number | 123. | 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