Code Beautifier
Unexpected non-whitespace character after JSON

Fix "Unexpected non-whitespace character after JSON"

The parser finished a complete JSON value and then found more text. The causes: two documents pasted together, a stray character, or a JSONL file.

Input that triggers it

{"id": 1, "name": "Ada"}
{"id": 2, "name": "Grace"}
Open JSON Formatter on its own page
Draft saved locally.

Local workspace

Named projects in IndexedDB · Local only — never synced to our servers. Worksp

Open manager

Batch workspace

Format multiple files locally in one run.

Indent:
json
json

What the error means

This one is different from most JSON errors: the document you pasted is valid. The parser read a complete value — an object, an array, a string, a number — reached its end, and then found more characters that are not whitespace. JSON allows exactly one top-level value per document, so anything after it is an error, and the position in the message points at the first character of the extra content.

In the example above, the first line is a perfect JSON object. The second line is another perfect JSON object. Together they are not a JSON document, and the parser fails at the { that starts line two.

Why it happens

  • Line-delimited JSON (JSONL / NDJSON). Log exports, bulk API responses, and dataset files often hold one JSON object per line. Each line parses; the whole file does not. This is the most common cause when the input looks obviously well-formed.
  • Two responses concatenated. A script that appended results to a file without a separator, or a copy that grabbed two payloads from a console.
  • A stray trailing character. A semicolon after a JavaScript-style assignment ({...};), a closing code fence, or a leftover , at the very end.
  • A prefix that was meant to be stripped. Some APIs return )]}',\n or while(1); before the JSON as an anti-hijacking guard; if that guard ends up after a value in your pipeline, or the value was sliced wrongly, this is the message.

How to fix it

  1. Paste the text into the formatter above. The error card names the position where the extra content begins; everything before it is a valid document.
  2. Decide which situation you are in. If there are several objects, one per line, use JSONL to JSON Converter, which turns them into an array in one step.
  3. If a single stray character or fence follows the value, delete it and format again.
  4. If you genuinely need several values in one document, wrap them: [ {...}, {...} ] with commas between the items.

The example, converted to a single document:

[
  { "id": 1, "name": "Ada" },
  { "id": 2, "name": "Grace" }
]

If it still fails

  • Check for a byte-order mark or a zero-width character between two values; the message will point at it even though your editor shows nothing there. String Inspector lists every invisible character by position.
  • If a response body comes from your own code, log its exact length and the last twenty characters before parsing. An extra } from a template or a doubled write shows up immediately.
  • Nothing you paste here is uploaded, so it is safe to check a payload from production directly.

Related errors