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.Unmarshalreturnsinvalid character '{' after top-level value. Ajson.Decoderreads several values in a row when you callDecodein a loop.
For the other parse errors, see common JSON errors.