tirth8205/code-review-graph · error · ValueError

expected colon after JSON object key

Error message

expected colon after JSON object key

What it means

Raised by _object_members when a string key token is not followed by a ':' token. The parser found a key-like string but no colon separating it from its value, so the object member is structurally incomplete. Like the other _object_members errors, it signals malformed JSONC at the edit target rather than a bad API argument.

Source

Thrown at code_review_graph/uninstall.py:282

            continue
        index += 1
    raise ValueError("unterminated JSON container")


def _object_members(tokens: Sequence[_Token], index: int) -> list[_Member]:
    if index >= len(tokens) or tokens[index].kind != "{":
        raise ValueError("expected JSON object")
    members: list[_Member] = []
    cursor = index + 1
    while cursor < len(tokens) and tokens[cursor].kind != "}":
        if tokens[cursor].kind == ",":  # trailing comma
            cursor += 1
            continue
        key_token = tokens[cursor]
        if key_token.kind != "string" or not isinstance(key_token.value, str):
            raise ValueError("expected JSON object key")
        if cursor + 1 >= len(tokens) or tokens[cursor + 1].kind != ":":
            raise ValueError("expected colon after JSON object key")
        value_index = cursor + 2
        value_end = _skip_value(tokens, value_index)
        comma_index = value_end if (
            value_end < len(tokens) and tokens[value_end].kind == ","
        ) else None
        members.append(
            _Member(key_token.value, cursor, value_index, value_end, comma_index)
        )
        cursor = value_end + 1 if comma_index is not None else value_end
    return members


def _array_elements(tokens: Sequence[_Token], index: int) -> list[_Element]:
    if index >= len(tokens) or tokens[index].kind != "[":
        raise ValueError("expected JSON array")
    elements: list[_Element] = []
    cursor = index + 1
    while cursor < len(tokens) and tokens[cursor].kind != "]":

View on GitHub (pinned to b58668751a)

Solutions

  1. Fix the missing/truncated colon so every key is '"key": value'
  2. If the file was truncated, restore it from backup/VCS before retrying the uninstall
  3. Validate with json.loads on comment-stripped content before running removal
  4. Wrap the removal call in try/except ValueError and leave the file unmodified on failure

Example fix

// before
{ "mcpServers" }  // -> expected colon after JSON object key

// after
{ "mcpServers": {} }
Defensive patterns

Strategy: validation

Validate before calling

import json, re
def object_members_wellformed(text: str) -> bool:
    try:
        json.loads(re.sub(r"//[^\n]*|/\*.*?\*/", "", text, flags=re.S))
        return True
    except ValueError:
        return False

Try / catch

try:
    _remove_jsonc_paths(text, paths)
except ValueError as e:
    if 'colon' in str(e):
        restore_from_backup()

Prevention

When it happens

Trigger: An object like {"key"} or {"key" , "other": 1} — a string followed by anything other than ':'. Also triggered when the token stream ends right after the key (cursor + 1 >= len(tokens)), e.g. a file truncated mid-object.

Common situations: Truncated config file from a crashed earlier write; user deleted a colon while hand-editing; merge conflict resolution left broken syntax; JSON5/JS-style shorthand value written by mistake.

Related errors


AI-assisted analysis of tirth8205/code-review-graph@b58668751a (2026-08-28). Data as JSON: /api/errors/402327a4c6cc984a. Report an issue: GitHub.