Unexpected end of JSON input
Why 'Unexpected end of JSON input' happens and how to fix it. The document stops before it is finished, usually a missing closing brace or a truncated response.
Open the JSON formatterWhat the error looks like
Different engines word this differently. You may see any of these:
Why it happens
- The parser reached the end of the text while a bracket was still open, so something is missing from the end rather than wrong in the middle.
- A missing } or ] is the common cause when the document was written by hand.
- A truncated response is the common cause when it came over the network: a connection dropped, a stream was cut short, or a response was written to a buffer that was too small.
- Parsing an empty string produces this too, because a JSON document has to contain a value.
Example
{
"name": "My Mosaic",
"tags": ["android", "puzzle"
{
"name": "My Mosaic",
"tags": ["android", "puzzle"]
}
How this tool reports it
The formatter points at the bracket that was left open rather than at the end of the file, and offers to close the open structures for you.
Paste your JSON into the formatter to see the exact line and column, or use the validator if you only need to check it.
Worth knowing
- If the JSON came from a network response, compare its length against the Content-Length header before assuming the document is malformed.