Skip to content

JavaScript · browsers and Node.js

Unexpected non-whitespace character after JSON at position N

JSON.parse throws Unexpected non-whitespace character after JSON when it finishes one complete value and then finds more text, where only whitespace may follow.

Updated · 2 min read

console
Chrome, Edge, Node.jsSyntaxError: Unexpected non-whitespace character after JSON at position 62 (line 2 column 1)
Node.js 20SyntaxError: Unexpected non-whitespace character after JSON at position 62
Node.js 18, older ChromeSyntaxError: Unexpected token { in JSON at position 62
FirefoxSyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 2 column 1 of the JSON data
SafariSyntaxError: JSON Parse error: Unable to parse JSON string

Find it in your JSON

Paste the text that failed. The checker points at the exact spot, and Repair fixes most syntax mistakes.

Input · JSON

Invalid JSON

Line 2, column 1

Unexpected '{' after the end of the JSON value.

1{"event":"signup","user":"u_481","ts":"2026-11-02T09:14:07Z"}2{"event":"login","user":"u_481","ts":"2026-11-02T09:15:42Z"} ^

Fix: JSON allows one top-level value. For several, wrap them in [ ] separated by commas. One object per line is JSON Lines (NDJSON).

Why this happens
Invalid JSONRuns in your browser

Load from a URL

Your browser fetches it directly, so the server must allow cross-origin requests (CORS).

Why it happens

A JSON document holds exactly one value, and the position points at the first character after it. Ranked by how often they turn up:

1. JSON Lines read as one document. Log exports, .jsonl files, batch API results and many streaming endpoints put one object per line. The sample fails at position 62 (line 2 column 1): a 61-character first line, a line break, then the second {.

2. Two values glued together. fs.appendFileSync('events.json', JSON.stringify(event)) produces {...}{...} on its second run. A stream chunk that carries two messages does the same.

3. One closing bracket too many. {"plan":"pro"}} fails on the second }. Hand edits and merge conflicts leave these behind.

4. Text after the JSON. A WordPress AJAX handler that does not exit lets admin-ajax.php print 0 after your output, so {"success":true}0 fails at position 16. A PHP notice or a debug print after the JSON does the same.

5. A value that only starts like JSON. JSON.parse('2026-11-05') reads 2026 as a number and fails at position 4, on the dash. Version strings and phone numbers behave the same way; store them with JSON.stringify or read them as plain strings.

How to fix unexpected non-whitespace character after JSON

Parse JSON Lines line by line

const events = text
  .split('\n')
  .filter((line) => line.trim() !== '')
  .map((line) => JSON.parse(line));

Skip blank lines: JSON.parse('') throws Unexpected end of JSON input. For large files in Node.js, stream them:

import { createReadStream } from 'node:fs';
import { createInterface } from 'node:readline';

const lines = createInterface({ input: createReadStream('events.jsonl'), crlfDelay: Infinity });
for await (const line of lines) {
  if (line.trim()) console.log(JSON.parse(line).event);
}

In Python, call json.loads per line; an empty line raises JSONDecodeError: Expecting value. jq -s '.' events.jsonl > events.json turns the file into one array.

Write one value per document

Read the file, add to the array and write the whole array back, or use JSON Lines on purpose: append JSON.stringify(event) + '\n' and read it back line by line.

End WordPress AJAX handlers properly

add_action('wp_ajax_save_note', function () {
    $note = sanitize_text_field($_POST['note'] ?? '');
    update_user_meta(get_current_user_id(), 'note', $note);
    wp_send_json_success(['saved' => true]);   // prints JSON and exits
});

Extra brackets and stray text

The JSON validator names the leftover character, for example Unexpected '}' after the end of the JSON value. JSON Repair removes a surplus closing bracket and wraps newline-separated objects in an array; objects glued together on one line need line breaks or commas first.

Same error in other languages

  • Python: json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 62) for the sample.
  • Go: json.Unmarshal returns invalid character '{' after top-level value. A json.Decoder reads several values in a row when you call Decode in a loop.

For the other parse errors, see common JSON errors.

Questions

Is a JSON Lines file valid JSON?

Each line is. The file as a whole is not, because a JSON document holds one top-level value. Tools that accept .jsonl or NDJSON read it one line at a time.

Does whitespace after the JSON cause this?

No. Spaces, tabs, line breaks and carriage returns may follow the value. Other invisible characters do trigger it: a non-breaking space, or NUL bytes left over from a fixed-size buffer.

Why does Safari only say "Unable to parse JSON string"?

When text remains after the value, Safari's parser stops without recording a reason and falls back to its generic message. The cause is the same as in Chrome.

Related errors

All common JSON errors

Esc