Expected ',' or '}' after property value in JSON
SyntaxError: Expected ',' or '}' after property value in JSON at position 31 (line 4 column 3)
Where it stops
"name": "Ada"
"email": "ada@example.com",
"active": trueWhat it means
JSON.parse read a value, and the next character was not a comma or a closing brace. Usually a comma is missing. The other common cause is a double quote inside a string, which ended the string early. The position is the first character the parser could not use, so look just before it.
Last verified on Chromium 145, Firefox 146, WebKit 26 and Node 20.
The validator opens with the error marked. Examples travel in the URL fragment, which browsers never send to a server.
Express Lint lays broken JSON out by bracket depth and marks the line where it stops. It changes only spaces and line breaks outside strings. Strings in either quote stay as written. If the quotes do not pair up, it leaves your text as it is. Ctrl+Z undoes it. See how it works.
- Usually
- A comma is missing between two membersA double quote inside a stringA missing comma in an arrayThe document stops after a valueSafari says only Expected '}'
- Fix
- Add the comma at the end of the line above the position, as in the fixed example.
The fix
Add the comma at the end of the line above the position, as in the fixed example. If that line already ends in a comma, look for a double quote inside a string just before the position and escape it.
{
"id": 7,
"name": "Ada"
"email": "ada@example.com",
"active": true
}Line 3: add ,.
{
"id": 7,
"name": "Ada",
"email": "ada@example.com",
"active": true
}How the message appears
Chrome and Node first, then Firefox, then Safari. The next three are the same fault in an array. The line after those is Chrome for an unescaped quote inside a string. Node 20 leaves out the line and column. Safari never says a comma is missing.
- SyntaxError: Expected ',' or '}' after property value in JSON at position 31 (line 4 column 3)Chrome and Node
- SyntaxError: JSON.parse: expected ',' or '}' after property value in object at line 4 column 3 of the JSON dataFirefox
- SyntaxError: JSON Parse error: Expected '}'Safari
- SyntaxError: Expected ',' or ']' after array element in JSON at position 3 (line 1 column 4)
- SyntaxError: JSON.parse: expected ',' or ']' after array element at line 1 column 4 of the JSON data
- SyntaxError: JSON Parse error: Expected ']'
- SyntaxError: Expected ',' or '}' after property value in JSON at position 21 (line 1 column 22)
- SyntaxError: Expected ',' or '}' after property value in JSON at position 31Older V8 wording
What causes it
A comma is missing between two members
The example has no comma after
"Ada". The other members have their commas.JSON.parsereads"Ada", then meets the"of"email"on the next line and stops. So the position is that quote, on line 4, and the line you have to edit is the one above it, line 3. Add the comma at the end of that line.A double quote inside a string
Take
{"quote": "she said "hi" to me"}. The quote beforehiends the string"she said ", so the next character is theh, and Chrome points at it. The mistake is the quote just before the position, not the text at the position. Escape the quote as\".A missing comma in an array
In a list the message says
after array elementand asks for,or].[1 2]stops at the2. Firefox says the same thing in its own words. Safari says onlyExpected ']'.The document stops after a value
Chrome and Node give this message when a body is cut off right after a value, and the position is the end of the text. If the position is the last character, look for a response that was cut short. See Unexpected end of JSON input.
Safari says only Expected '}'
Safari does not say that a comma is missing. It says
Expected '}'for a missing comma and for an unquoted key, so the message alone does not tell you which. Look at the character before the spot. If a value ends there, add a comma. If a{or a comma is there, the key needs double quotes. See Unquoted property names.
Worth knowing
NotePython words the same fault Expecting ',' delimiter. See the Python page.
NoteIf you build JSON by joining strings, one value with a quote in it gives this error. JSON.stringify escapes the quote for you.