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
- VS Code:
Property keys must be doublequotedfor an unquoted key,Value expectedfor an unquoted value, and Comments are not permitted in JSON for comments. - Chrome and Node.js: an unquoted key gives Expected property name or ‘}’ in JSON.
- Python:
Expecting valueat the position of the bare word, as in the console above.
Paste a file into the JSON validator to find the first bad token without opening the IDE. More messages: common JSON errors.