Why it happens
The message only fires right after {; the same mistake after a comma gives Expected double-quoted property name. At position 1, the culprit is the character after the very first brace. What usually sits there:
1. Single quotes from a Python dict. str(payload), print(payload) and f-strings write Python syntax: single quotes and True, False, None. The sample is the str() of a sensor reading sent to a Node.js service:
payload = {"device": "th-07", "temp_c": 21.5, "online": True}
requests.post(url, data=str(payload)) # sends {'device': 'th-07', ...}
2. Unquoted keys from JavaScript. Object literals, hand-written config, and console.log output, which Node.js prints as { device: 'th-07', temp_c: 21.5 }. The space after { moves the error to position 2 (line 1 column 3).
3. A shell removed the double quotes. On Windows, curl.exe -d '{"device":"th-07"}' in Windows PowerShell 5.1, or the double-quoted version in cmd.exe, reaches the server as {device:th-07}.
4. A comment or a stray comma. { // sensor config or {,. tsconfig.json and VS Code’s settings accept comments; JSON.parse does not.
The checker tells these apart: Keys must use double quotes, not single quotes, Key device must be in double quotes, or Comments are not allowed in JSON.
How to fix Expected property name or ‘}’
Python senders
import requests
payload = {"device": "th-07", "temp_c": 21.5, "online": True}
requests.post("https://api.example.com/readings", json=payload)
json= writes real JSON and sets Content-Type: application/json. For files and strings, use json.dump() and json.dumps(). To convert Python-style text you already have, use json.dumps(ast.literal_eval(text)) rather than search and replace.
JavaScript
Log JSON.stringify(obj, null, 2) to print an object as JSON. Import data from a .js file as a module instead of parsing it.
curl and PowerShell
Let curl read the body from a file, which avoids shell quoting:
curl -X POST https://api.example.com/readings -H "Content-Type: application/json" -d "@reading.json"
In PowerShell, build the body as an object:
$body = @{ device = 'th-07'; temp_c = 21.5; online = $true } | ConvertTo-Json
Invoke-RestMethod -Uri https://api.example.com/readings -Method Post -ContentType 'application/json' -Body $body
PowerShell 7.3 and later pass embedded double quotes to native programs such as curl.exe correctly.
Express: answer bad JSON with a 400
express.json() passes the SyntaxError to your error handler:
app.use((err, req, res, next) => {
if (err.type === 'entity.parse.failed') {
return res.status(400).json({ error: 'Request body is not valid JSON', detail: err.message });
}
next(err);
});
Comments and one-off fixes
Delete the comment, or paste the text into JSON Repair, which swaps single quotes for double quotes, quotes bare keys, strips comments and turns True into true. Check the output in the JSON validator.
Same error in other languages
- Python:
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1) - Go:
invalid character '\'' looking for beginning of object key string - Editors: JetBrains IDEs flag non-standard syntax as you type, for example JSON standard does not allow such tokens, and VS Code marks comments with Comments are not permitted in JSON.
More causes of failed parses: common JSON errors.