JSONWeave

JSONWeave / Guides

Processed entirely in your browser

How to fix truncated or incomplete JSON

By Abhishek Jaiswar ยท Published

A truncated JSON document ends before its objects and arrays are closed. The structure can often be completed. The missing data cannot.

Repair JSON in JSONWeave

How to recognise truncation

Parsers report truncation differently, but the wording is similar: "Unexpected end of JSON input" in JavaScript, "Expecting value" or "Unterminated string" in Python. All of them mean the parser reached the end of the text while it still expected more.

Check the last characters of the document. If it ends in the middle of a key, a string or after a comma, the text was cut off rather than mistyped.

Cut off inside a string
{
  "id": 7,
  "message": "Payment recei

Common causes

  • A log system or terminal truncated a long line.
  • A response was read before the connection finished, or a client stopped at a size limit.
  • A copy and paste missed the last lines.
  • A streaming API sent JSON in chunks and one chunk was lost.

Close the structure

Work backwards from the end. Finish the open string with a quote, remove a dangling comma or key that has no value, then close every open array with ] and every open object with } in the reverse order they were opened.

Truncated
{"items": [{"id": 1}, {"id": 2, "tags": ["a", "b"
Closed
{"items": [{"id": 1}, {"id": 2, "tags": ["a", "b"]}]}

Do it automatically, and check the result

JSONWeave reports each unclosed object and array and previews the completed document, so you do not have to count brackets by hand. Treat the result as the part of the data that arrived. Records after the cut are gone, and the last record may be incomplete. If the data matters, fix the cause of the truncation and request it again.

Related

Ready to try it on your own JSON?

Open the workspace, paste or drop a file, and nothing leaves your browser.

Repair JSON in JSONWeave