Expected ',' or '}' after property value in JSON

ErrorJavaScript

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": true

What 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.

It opens with the error marked. Nothing is uploaded. Find where the error is.

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.

broken.jsonFails to parse
{
  "id": 7,
  "name": "Ada"
  "email": "ada@example.com",
  "active": true
}
JSON.parse stops at line 4, column 3.

Line 3: add ,.

fixed.jsonParses
{
  "id": 7,
  "name": "Ada",
  "email": "ada@example.com",
  "active": true
}
JSON.parse reads it.

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.

Console
  • 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

  1. A comma is missing between two members

    The example has no comma after "Ada". The other members have their commas. JSON.parse reads "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.

  2. A double quote inside a string

    Take {"quote": "she said "hi" to me"}. The quote before hi ends the string "she said ", so the next character is the h, and Chrome points at it. The mistake is the quote just before the position, not the text at the position. Escape the quote as \".

  3. A missing comma in an array

    In a list the message says after array element and asks for , or ]. [1 2] stops at the 2. Firefox says the same thing in its own words. Safari says only Expected ']'.

  4. 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.

  5. 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.

What you put into the tools never leaves your browser. We count page views and keep them for 90 days. Accept and we also remember this browser, so a return visit is not counted as new. Privacy policy