fjordtools / Errors / Unexpected token ' in JSON

Unexpected token ' in JSON at position 1

The parser met a single quote where JSON needs a double quote. In JSON every key and every string is wrapped in double quotes, and single quotes are never allowed. The text is usually a JavaScript object literal or a printed Python dictionary, not JSON. Convert it with JSON.stringify or json.dumps.

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

How browsers word it

Chrome and Node (V8), newerExpected property name or '}' in JSON at position 1 (line 1 column 2)
Chrome and Node, olderUnexpected token ' in JSON at position 1
FirefoxJSON.parse: expected property name or '}' at line 1 column 2 of the JSON data
SafariJSON Parse error: Expected '}'

Common causes

  1. A printed Python dictionary

    print(my_dict) writes single quotes, and True and None instead of true and null. That is Python syntax, not JSON.

    Input

    {'ok': True}

    JSON Formatter says

    Single quotes are not valid JSON. Use double quotes around keys
  2. A JavaScript object literal

    Code often uses single quotes for strings. They are fine in JavaScript, but JSON.parse only accepts double quotes.

    Input

    {"a": 'x'}

    JSON Formatter says

    Single quotes are not valid JSON. Use double quotes
  3. Keys without quotes

    JavaScript allows {a: 1}. JSON does not: every key needs double quotes.

    Input

    {a: 1}

    JSON Formatter says

    Expected a key in double quotes but found "a". Keys must be quoted

How to fix it

  1. In Python write JSON with json.dumps(value), not str(value) or print(value).
  2. In JavaScript write JSON with JSON.stringify(value), not a hand-typed string.
  3. To fix a short text by hand, replace every single quote with a double quote, and True, False and None with true, false and null.
  4. Paste the text into the JSON formatter to find any other problem.

Related errors

More error explainers are coming

See all errors.