Unexpected Non-Whitespace Character After JSON: How to Fix It

If you got this error:

SyntaxError: Unexpected non-whitespace character after JSON at position 15

the parser already managed to interpret a valid JSON, but then it found something extra after it that shouldn’t be there. Unlike “unexpected end of JSON input” (which is about something missing), this one is about having leftover content after the JSON already ended.

Notice that the position shown in the error is right after where the valid JSON would have ended. That’s exactly where the problem is.

The most common causes

1. Multiple JSON objects concatenated without a separator

// javascript
JSON.parse('{"a": 1}{"b": 2}'); // error: the second object is leftover

JSON.parse() manages to parse the first {"a": 1} just fine, but then it runs into {"b": 2} left over, with nothing indicating it’s part of the same structure. JSON has no concept of “multiple documents” in a single string, unless you use a format built for that, like JSON Lines (JSONL), which separates each object with a line break and treats each line as an independent parse.

How to fix it: if you really do have multiple objects, one option is wrapping them in an array.

// javascript
JSON.parse('[{"a": 1}, {"b": 2}]'); // valid

2. Extra text accidentally appended at the end of the string

// javascript
JSON.parse('{"name": "test"} extra text here');

This is common when the JSON comes from a source that mixes formats, for example a log that prints the JSON and then adds a suffix, or a manual copy-paste that accidentally brought along extra characters.

3. API response with the JSON followed by other content

Similar to case 2, but in a networking context: sometimes an API returns the correct JSON, but the response body has something extra at the end, like a line break followed by other content (a server log, a debug footer, etc.) that shouldn’t be part of the response.

// javascript
fetch('/api/data')
  .then(res => res.text())
  .then(text => {
    console.log(JSON.stringify(text)); // check for anything after the final } or ]
    const data = JSON.parse(text);
  });

If logging the string shows characters after the expected closing bracket, the problem is in the source of the response, not in your parsing code.

4. JSON Lines (JSONL) format treated as regular JSON

If you’re dealing with a file or stream in JSONL format (where each line is an independent JSON document), calling JSON.parse() on the whole file at once will always trigger this error, because technically it’s several valid JSON documents in a row, separated by line breaks.

// This is JSONL, not JSON:
// {"a": 1}
// {"b": 2}

// Wrong: trying to parse everything at once
JSON.parse(fileContent);

// Right: parse line by line
const lines = fileContent.split('\n').filter(line => line.trim() !== '');
const objects = lines.map(line => JSON.parse(line));

Quick checklist

  • Does your string have more than one JSON object or array pasted together without a separator?
  • Is there extra text left over after the final closing } or ]?
  • If it’s an API response, log the raw string and check there’s nothing after the expected JSON
  • If the content is JSONL, remember to parse it line by line, not the whole file at once

To quickly spot exactly where the extra content starts, paste the string into JSON Validator and see the highlighted position.