Skip to content

Editors, CLI and databases

JSON standard does not allow such tokens

The IDE found a bare word without quotes where standard JSON only allows a string, a number, true, false or null.

Updated · 2 min read

console
IntelliJ IDEA, PyCharm, WebStormJSON standard does not allow such tokens
Same inspection, on a commentJSON standard does not allow comments.
Python json, same filejson.decoder.JSONDecodeError: Expecting value: line 3 column 13 (char 34)
Safari, same fileSyntaxError: JSON Parse error: Unexpected identifier "shipped"

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 3, column 13

Unexpected word shipped. Strings need double quotes.

1{2  "carrier": "UPS",3  "status": shipped,             ^4  "signedBy": None,

Fix: If it is text, write "shipped".

Invalid JSONRuns in your browser

Load from a URL

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

Why the JSON standard does not allow such tokens

JetBrains IDEs show JSON standard does not allow such tokens when a .json file contains a bare word. The IDE reads any unquoted run of letters, digits and symbols such as ., -, /, @ and ^ as one token, and the Compliance with JSON standard inspection marks it, because JSON has no bare words except true, false and null.

1. Unquoted keys or text. Objects copied from JavaScript or YAML, where both sides of status: shipped are flagged.

2. Literals from another language. undefined from JavaScript; None, True and False from Python; nil and NULL. JSON writes them null, true and false, in lowercase.

3. Numbers JSON cannot hold. A leading zero (02134, 007), hex (0xFF), an unquoted date (2024-05-01) or a version range (^4.19.2). The IDE takes the longest run, so 2024-05-01 is one bad token, not a number followed by junk.

How to fix it

Quote text, rewrite literals

Put the caret on the token, press Alt + Enter (⌥ + Return on macOS) and choose Wrap with double quotes. Do that for keys and text only: on None it produces the string "None". Type null, true or false there instead. F2 jumps to the next error in the file.

The checker above stops at the first problem. Repair, there or in JSON Repair, fixes all three in the sample and keeps the zip code as text:

{
  "carrier": "UPS",
  "status": "shipped",
  "signedBy": null,
  "zip": "02134"
}

If a script writes the file, fix the script. Python’s str(data) writes None, True and single quotes; json.dumps(data) writes JSON. In JavaScript, use JSON.stringify instead of building the text by hand.

Mark real JSON5 files as JSON5

Some config files are JSON5 on purpose: unquoted keys, single quotes, comments, trailing commas, hex numbers and NaN are all valid there. Rename the file to .json5, or right-click it in the Project tool window, choose Override File Type and pick JSON5. To treat every .json file in a project as JSON5, add *.json to the JSON5 patterns under Settings | Editor | File Types.

JSON5 still rejects bare values like shipped or None and keys that are not valid identifiers, such as my-key, with the same message. Switch only when the program that reads the file parses JSON5. package.json and API payloads must stay standard JSON.

Comments

For JSON standard does not allow comments., rename the file to .jsonc: the IDE accepts comments there and keeps every other check. You can also switch it to JSON5, or clear Warn about comments in Settings | Editor | Inspections | JSON and JSON5 | Compliance with JSON standard. Either way, the reader must accept comments too: see can JSON have comments.

Same error in other tools

Paste a file into the JSON validator to find the first bad token without opening the IDE. More messages: common JSON errors.

Questions

Can I switch this check off?

Only by disabling the whole Compliance with JSON standard inspection. Comments, trailing commas, NaN and multiple top-level values each have an option; bare words do not. Disabling it also hides real mistakes.

Why does NaN get a different message?

The IDE reads NaN, Infinity and -Infinity as numbers and reports them as Illegal floating point literal. Standard JSON parsers reject them all the same.

What does "JSON standard allows only double quoted string as property key" mean?

The key is a number or a single-quoted string, such as 42 or 'id'. An unquoted word as a key gets "does not allow such tokens" instead.

Related errors

All common JSON errors

Esc