JSON errors

JavaScript, from JSON.parse()

Unexpected non-whitespace character after JSON

The parser read one complete JSON value and then found more text after it. JSON.parse accepts exactly one value, so a second object, a log line or even a stray character after the closing brace is an error.

How each browser and language words it

Chrome, Edge and Node 20+
SyntaxError: Unexpected non-whitespace character after JSON at position 44 (line 2 column 1)
Older Chrome and Node 18 and below
SyntaxError: Unexpected token { in JSON at position 44
Firefox
SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 2 column 1 of the JSON data
Python
json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 44)

Paste your JSON to find the exact line

Three JSON values on three lines. Press Repair to wrap them into one array.

Skip to editor
Explorer
Open Files

No files open

0 files open

jsoneditor.io v2

{"id": 1, "event": "signup", "user": "ada"}
{"id": 2, "event": "login", "user": "ada"}
{"id": 3, "event": "purchase", "user": "ada", "total": 89.99}
JSONUTF-8
Spaces: 2

Causes and how to fix each one

1. The file is JSON Lines (one object per line)

Logs, exports and streaming APIs often use JSON Lines, also called NDJSON, where each line is its own JSON value. Parse it line by line, or press Repair to wrap the lines into one array.

JavaScript
const records = text
  .split('\n')
  .filter((line) => line.trim())
  .map((line) => JSON.parse(line))

2. Two JSON documents written to the same file

Appending to a file instead of rewriting it, or a server that writes two responses into one body, leaves two objects back to back. Decide which one you want, or collect them in an array.

3. A stray character after the closing brace

An extra } from a bad edit, a trailing semicolon copied from code or a debug message printed to the same output all show up as text after the JSON. The position in the error points straight at it.

Questions people ask

What is the difference between JSON and JSON Lines?

A JSON file holds exactly one value, often an array. A JSON Lines file holds one complete JSON value per line, which makes it easy to append to and stream, but it has to be parsed one line at a time.

Does whitespace after the JSON cause this error?

No, spaces, tabs and newlines after the value are allowed. Only visible characters trigger it, which is what non-whitespace means.

Tools for this