How does the partial parser repair JSON?
It reads the text as normal JSON. When the text stops early, it remembers what was still open at that moment and closes it, innermost first:
- Find the start: skip everything before the first
{or[, such as a log timestamp or a```jsonline. - Read until the text ends, keeping a list of the strings, objects and arrays that are open.
- Finish the value that was cut, if it can be finished honestly (see the table below).
- Add the closing
",}and]characters, and mark where the input ended.
For example, {"user": {"name": "Ana", "tags": ["admin", "edi becomes {"user": {"name": "Ana", "tags": ["admin", "edi"]}}, with "]}} added.
What happens at each kind of cut
| Input ends | Example | Result |
|---|---|---|
| Inside a string | {"a": "hel | {"a": "hel"} |
| Inside a key | {"a": 1, "na | {"a": 1}, key left out |
| After a colon | {"name": | {}, key left out |
| After a comma | [1, 2, | [1, 2], comma removed |
| Inside a number | [1, 12. | [1, 12] |
| Inside true, false or null | [tru | [true] |
| Inside an escape | {"s": "x\u00 | {"s": "x"}, escape left out |
Nothing is invented: a value is only completed when there is one possible ending. A key without a value is left out instead of being given null, and every change is listed under the result.
Where truncated JSON comes from
- Streaming model output. A model that streams JSON sends it in pieces. Parsing what has arrived so far lets you show partial results, and an answer cut off by a token limit ends mid-value.
- Log lines. Many logging setups cut long lines at a fixed length, so a logged request body loses its end.
- Copy and paste. Copying from a terminal or a size-limited preview often misses the last lines.
Limitations
- Only a missing end is repaired. A syntax error earlier in the text, such as a missing comma or a single-quoted string, is reported with its line and column instead.
- The last number is kept as written but flagged, because the parser cannot know whether more digits followed.
- Only the first JSON value in the text is read. Text after a complete value is ignored and noted.
- The repaired JSON is always pretty-printed with two spaces. Use the JSON Formatter to minify or re-indent it.
Questions
How do I fix JSON that was cut off?
Paste it here. The parser reads up to where the text stops, closes every string, object and array that is still open, and gives you valid JSON to copy. It lists each character it added, innermost first.
Can I paste a whole log line or a model answer?
Yes. Text before the first { or [ is skipped, so a timestamp prefix or a ```json code fence can stay. A bracketed log prefix such as [INFO] or [2024-05-01 12:00:00] is not JSON, so the parser moves on to the next { or [.
What happens to a key or value that was cut in half?
A cut string keeps the text it has and gets a closing quote. A cut literal such as tru is completed to true. A cut key, a key without a value, a lone minus sign and a half-written escape sequence are left out, and the list says so.
Why does it say the last number may be incomplete?
A number that runs into the end of the input, such as 12 in [1, 12, cannot be told apart from the start of 120 or 12.5. It is kept as written and flagged, so you know not to trust it.
What if the JSON has a real syntax error?
Closing brackets only fixes text that stops early. An error before the end, such as a missing comma, is shown with its line, column and the offending line, the same way as in the JSON Formatter.
Support this site
The tools are free and need no account. If one saved you time, a small donation helps keep them running.
Want a tool or feature? Suggest it for free, or donate and write your request in the message. Supporters' requests are looked at first.