Skip to content

JavaScript · browsers and Node.js

Expected property name or '}' in JSON at position 1 (line 1 column 2)

Expected property name or '}' in JSON means the parser found something other than a double-quoted key or a closing } right after an opening {.

Updated · 2 min read

console
Chrome, Edge, Node.jsSyntaxError: Expected property name or '}' in JSON at position 1 (line 1 column 2)
Node.js 20SyntaxError: Expected property name or '}' in JSON at position 1
Node.js 18, older ChromeSyntaxError: Unexpected token ' in JSON at position 1
FirefoxSyntaxError: JSON.parse: expected property name or '}' at line 1 column 2 of the JSON data
Safari, single quotesSyntaxError: JSON Parse error: Single quotes (') are not allowed in JSON
Safari, unquoted keySyntaxError: JSON Parse error: Expected '}'

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 1, column 2

Keys must use double quotes, not single quotes.

1{'device': 'th-07', 'temp_c': 21.5, 'online': True}  ^

Fix: Replace the single quotes with double quotes, or use Repair.

Why this happens
Invalid JSONRuns in your browser

Load from a URL

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

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

More causes of failed parses: common JSON errors.

Questions

Why position 1 and not 0?

Positions count from 0 and the { is position 0, so the character after it is 1. Lines and columns count from 1, which makes the same spot column 2.

Is there a parser that accepts this?

JSON5 accepts unquoted keys, single quotes, comments and trailing commas, through the json5 npm package. Use it for files people edit by hand, not for data you exchange with other systems.

Why does the same text work in the browser console?

Typed at the console prompt, {device: 'th-07'} runs as a JavaScript object literal, which allows both forms. JSON.parse follows the stricter JSON grammar.

Related errors

All common JSON errors

Esc