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.

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.

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.

Your JSON and text are processed entirely in your browser and are never sent anywhere. To understand how the site is used we record each page view (the page, the referrer and an approximate location from your IP address) and keep it for 90 days. Nothing is stored on your device unless you choose it. Accept to also store a device identifier here and record your browser and device characteristics, which is what lets a return visit be told from a new one. Decline and nothing is sent at all. We respect Do Not Track. See our privacy policy.