JSON WalletPrivacy-first JSON & API workspace

Fix "Unexpected end of JSON input"

JavaScript / Node.js ยท JSON error

โ† All tools

Unexpected end of JSON inputSyntaxError: Unexpected end of JSON inputJSON.parse: unexpected end of data

Opens the editor with a broken example loaded and repaired, entirely in your browser โ€” nothing is uploaded.

What causes it

This error means the parser ran out of input before the document was complete. There are three common causes:

  • An empty string. Calling JSON.parse('') throws immediately. This happens when a fetch returns a 204 No Content, a failed request, or a body you already consumed once.
  • A truncated response. The connection dropped or the server cut the body short, so the closing } or ] never arrived.
  • A genuinely unbalanced document โ€” a missing closing brace, bracket, or quote that you can fix by hand.

How to fix it

  1. Check the response is not empty and the status is not 204 before parsing.
  2. Guard with: const text = await res.text(); const data = text ? JSON.parse(text) : null.
  3. If the body is truncated, look for a network timeout or a server that streamed an incomplete response.
  4. Paste the text into JSON Wallet โ€” the tree view shows exactly which bracket or quote is left unclosed, and Repair can balance it.

Before and after

Broken:

{
  "id": 1,
  "tags": ["a", "b"

Fixed:

{
  "id": 1,
  "tags": ["a", "b"]
}

Want to fix your own JSON instead of the example? Open the editor, paste it in, and click Repair โ€” it runs entirely in your browser.

Frequently asked questions

Why does an empty response cause this error?

JSON.parse('') has nothing to parse, so it fails at the end of input. Always check for an empty body (for example a 204 status) before parsing.

How do I find the missing bracket?

Paste the JSON into the editor and switch to tree view. The branch that never closes will fail to render, pointing you straight at the unbalanced structure.


Related JSON errors

For a full reference of JSON mistakes, read Common JSON errors and how to fix them.

Press โŒ˜ K for commands