JuliusBrussee/caveman · error · ValueError

comma

Error message

comma

What it means

ValueError from the hand-rolled JSON walker in _google_wire.py: after a key/value pair inside an object, the next character was neither ',' (more pairs) nor '}' (end of object). The message names the expected separator token ('comma').

Solutions

  1. Repair the JSON by inserting the missing ',' between members
  2. Validate with json.loads before calling parse to pinpoint the syntax error
  3. Check the transport/producer for truncation and re-fetch the payload
  4. Catch ValueError and fall back to line-by-line JSON parsing for NDJSON input

Example fix

# before
value = parse('{"a": 1 "b": 2}')  # ValueError: comma
# after
value = parse('{"a": 1, "b": 2}')
Defensive patterns

Strategy: try-catch

Validate before calling

import json
def is_well_formed_json(text):
    try:
        json.loads(text)
        return True
    except json.JSONDecodeError:
        return False

Try / catch

try:
    value = parse(text)
except ValueError as e:
    if str(e) == "comma":
        raise ValueError("Malformed JSON object: expected ',' or '}' between members") from e

Prevention

When it happens

Trigger: Parsing JSON objects with missing commas between members ({"a":1 "b":2}), trailing content, or truncation right after a value, via parse().

Common situations: Truncated network payloads; string-templated JSON missing separators; newline-delimited JSON accidentally fed as a single document; manual edits removing commas.

Understand the failure class

Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/fedd70484b548faf. Report an issue: GitHub.

Appendix: source

Thrown at packages/middleware/python/caveman_middleware/_google_wire.py:49

                index += 1
                return result
            while True:
                white()
                key, index = decoder.raw_decode(text, index)
                if type(key) is not str or key in result:
                    raise ValueError("duplicate")
                white()
                if text[index] != ":":
                    raise ValueError("colon")
                index += 1
                result[key] = walk((*path, key), depth + 1)
                white()
                end = text[index]
                index += 1
                if end == "}":
                    return result
                if end != ",":
                    raise ValueError("comma")
        if text[index] == "[":
            index += 1
            result = []
            white()
            if text[index] == "]":
                index += 1
                return result
            while True:
                result.append(walk((*path, len(result)), depth + 1))
                white()
                end = text[index]
                index += 1
                if end == "]":
                    return result
                if end != ",":
                    raise ValueError("comma")
        value, index = decoder.raw_decode(text, index)
        return value

View on GitHub (pinned to 3ee70a1026)