JSONDecodeError: Expecting ',' delimiter (tested)

json.decoder.JSONDecodeError: Expecting ',' delimiter means the parser finished a value and the next character was not a comma or closing bracket. In our tests the three causes were a missing comma, an unescaped " inside a string, and truncated JSON. Tested on Python 3.13.5.

1. A missing comma between items

import json

text = '''[
  {"id": 1, "name": "apple"}
  {"id": 2, "name": "pear"}
]'''
json.loads(text)

Output:

Traceback (most recent call last):
  File "/tmp/jd/b1.py", line 7, in <module>
    json.loads(text)
    ~~~~~~~~~~^^^^^^
  File "/usr/lib/python3.13/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ~~~~~~~~~~~~~~~~~~~~~~~^^^
  File "/usr/lib/python3.13/json/decoder.py", line 345, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/json/decoder.py", line 361, in raw_decode
    obj, end = self.scan_once(s, idx)
               ~~~~~~~~~~~~~~^^^^^^^^
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 3 column 3 (char 33)

The parser finished the first object and expected a , or ]; it found { instead. The position (line 3, column 3) points at the token after the missing comma, so the comma belongs just before it.

2. An unescaped double quote inside a string

import json

text = '{"msg": "she said "hi" to me", "n": 1}'
json.loads(text)

Output:

Traceback (most recent call last):
  File "/tmp/jd/b2.py", line 4, in <module>
    json.loads(text)
    ~~~~~~~~~~^^^^^^
  File "/usr/lib/python3.13/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ~~~~~~~~~~~~~~~~~~~~~~~^^^
  File "/usr/lib/python3.13/json/decoder.py", line 345, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/json/decoder.py", line 361, in raw_decode
    obj, end = self.scan_once(s, idx)
               ~~~~~~~~~~~~~~^^^^^^^^
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 20 (char 19)

The string ended at the quote before hi, so the parser expected a comma at column 20 and found h. The JSON is not missing a comma here; the quote needed escaping (\"). This usually happens when JSON is built by string concatenation or f-strings.

3. Truncated JSON (cut-off download, file, or model output)

import json

full = json.dumps({"items": [1, 2, 3, 4], "ok": True})
for cut in (12, 18, len(full) - 1):
    try:
        json.loads(full[:cut])
    except json.JSONDecodeError as e:
        print(repr(full[:cut]), "->", e)

Output:

'{"items": [1' -> Expecting ',' delimiter: line 1 column 13 (char 12)
'{"items": [1, 2, 3' -> Expecting ',' delimiter: line 1 column 19 (char 18)
'{"items": [1, 2, 3, 4], "ok": true' -> Expecting ',' delimiter: line 1 column 35 (char 34)

When the text ends inside an array or object, the error is often Expecting ',' delimiter at the very last character. If the char position equals the length of your text, the data was cut off: check that the whole response or file was read (stream fully, check Content-Length, or raise the max output length if it came from an LLM).

4. Show exactly where it fails

import json

def show(text):
    try:
        return json.loads(text)
    except json.JSONDecodeError as e:
        line = text.splitlines()[e.lineno - 1]
        print(f"{e.msg} at line {e.lineno}, column {e.colno}:")
        print("  " + line)
        print("  " + " " * (e.colno - 1) + "^")

show('{\n  "a": 1,\n  "b": [1, 2 3],\n  "c": 3\n}')

Output:

Expecting ',' delimiter at line 3, column 14:
    "b": [1, 2 3],
               ^

JSONDecodeError has msg, lineno, colno and pos attributes. Printing the line with a caret finds the problem faster than counting characters (here, the missing comma between 2 and 3).

5. Fix: generate JSON with json.dumps

import json

msg = 'she said "hi" to me'
text = json.dumps({"msg": msg, "n": 1})
print(text)
print(json.loads(text)["msg"])

Output:

{"msg": "she said \"hi\" to me", "n": 1}
she said "hi" to me

json.dumps escapes quotes, backslashes and control characters for you, so its output always parses. Fix the producer rather than patching the text with regexes.

6. Related messages (and a Python 3.13 change)

import json

for text in ('{"a" 1}', '{"a": 1 "b": 2}', '{"a": 1,}', "{'a': 1}"):
    try:
        json.loads(text)
    except json.JSONDecodeError as e:
        print(f"{text!r:22} -> {e}")

Output:

'{"a" 1}'              -> Expecting ':' delimiter: line 1 column 6 (char 5)
'{"a": 1 "b": 2}'      -> Expecting ',' delimiter: line 1 column 9 (char 8)
'{"a": 1,}'            -> Illegal trailing comma before end of object: line 1 column 8 (char 7)
"{'a': 1}"             -> Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

On Python 3.10 the same inputs give:

'{"a" 1}'              -> Expecting ':' delimiter: line 1 column 6 (char 5)
'{"a": 1 "b": 2}'      -> Expecting ',' delimiter: line 1 column 9 (char 8)
'{"a": 1,}'            -> Expecting property name enclosed in double quotes: line 1 column 9 (char 8)
"{'a': 1}"             -> Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

A missing colon gives Expecting ':' delimiter. A trailing comma is reported as Illegal trailing comma before end of object on Python 3.13, but as Expecting property name enclosed in double quotes on 3.10. Single-quoted keys (a Python str(dict)) give the property-name error on both; see Expecting property name enclosed in double quotes.

Related: Expecting value: line 1 column 1 (char 0) · JSONDecodeError: Extra data · all JSONDecodeError messages.

Frequently asked questions

What causes Expecting ',' delimiter in Python json?

A missing comma between items, an unescaped double quote inside a string (which ends the string early), or JSON that was cut off before the end.

How do I find where the JSON is broken?

Catch json.JSONDecodeError and use e.lineno, e.colno and e.pos; the position points at the token right after the missing comma.

What is the difference between Expecting ',' delimiter and Expecting ':' delimiter?

':' delimiter means a key was not followed by a colon, e.g. {"a" 1}. ',' delimiter means a value was not followed by a comma or closing bracket.

Written with AI assistance. Measured on 2026-10-23 with Python 3.13.5 (and python:3.10-alpine for the comparison). Each block was run verbatim and the output pasted unedited. PlainHeaders is our extension; Python is free.