fjordtools / Errors / Non-whitespace after JSON

Unexpected non-whitespace character after JSON at position 8

The parser read one complete JSON value and then found more text after it. A JSON document holds exactly one value, so two objects in a row, a file with one object per line, or a stray character after the closing brace all fail. Parse each line separately or wrap the values in an array.

Fjordtools team · Seen in Chrome and Node (V8) · Published · 1 min read

How browsers word it

Chrome and Node (V8)Unexpected non-whitespace character after JSON at position 8 (line 1 column 9)
Chrome and Node, olderUnexpected token { in JSON at position 8
FirefoxJSON.parse: unexpected non-whitespace character after JSON data at line 1 column 9 of the JSON data
SafariJSON Parse error: Unexpected content after JSON

Common causes

  1. Two values in a row

    Joining two JSON texts gives something that is no longer one JSON document.

    Input

    {"a": 1} {"b": 2}

    JSON Formatter says

    Unexpected "{" after the end of the JSON value
  2. One object per line (NDJSON)

    Log files and streaming APIs often write one JSON object per line. Each line is valid JSON on its own, but the whole file is not.

    Input

    {"a": 1}
    {"b": 2}

    JSON Formatter says

    Unexpected "{" after the end of the JSON value
  3. A stray character at the end

    A leftover character, a second closing bracket or a pasted prompt sign can follow the value.

    Input

    {"a": 1}x

    JSON Formatter says

    Unexpected "x" after the end of the JSON value
  4. Two arrays

    Pasting two lists one after the other has the same problem.

    Input

    [1, 2] [3]

    JSON Formatter says

    Unexpected "[" after the end of the JSON value

How to fix it

  1. For one object per line, split the text on newlines and parse each non-empty line on its own.
  2. To keep everything in one document, wrap the values in an array and separate them with commas.
  3. Remove a stray character after the final closing brace or bracket.
  4. Paste the text into the JSON formatter to see where the first value ends.

Related errors

More error explainers are coming

See all errors.