{"record":{"id":"739ee442e59338de","repo":"tirth8205/code-review-graph","slug":"expected-json-object-key","errorCode":null,"errorMessage":"expected JSON object key","messagePattern":"expected JSON object key","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"code_review_graph/uninstall.py","lineNumber":280,"sourceCode":"        elif kind in (\"{\", \"[\"):\n            index = _skip_value(tokens, index)\n            continue\n        index += 1\n    raise ValueError(\"unterminated JSON container\")\n\n\ndef _object_members(tokens: Sequence[_Token], index: int) -> list[_Member]:\n    if index >= len(tokens) or tokens[index].kind != \"{\":\n        raise ValueError(\"expected JSON object\")\n    members: list[_Member] = []\n    cursor = index + 1\n    while cursor < len(tokens) and tokens[cursor].kind != \"}\":\n        if tokens[cursor].kind == \",\":  # trailing comma\n            cursor += 1\n            continue\n        key_token = tokens[cursor]\n        if key_token.kind != \"string\" or not isinstance(key_token.value, str):\n            raise ValueError(\"expected JSON object key\")\n        if cursor + 1 >= len(tokens) or tokens[cursor + 1].kind != \":\":\n            raise ValueError(\"expected colon after JSON object key\")\n        value_index = cursor + 2\n        value_end = _skip_value(tokens, value_index)\n        comma_index = value_end if (\n            value_end < len(tokens) and tokens[value_end].kind == \",\"\n        ) else None\n        members.append(\n            _Member(key_token.value, cursor, value_index, value_end, comma_index)\n        )\n        cursor = value_end + 1 if comma_index is not None else value_end\n    return members\n\n\ndef _array_elements(tokens: Sequence[_Token], index: int) -> list[_Element]:\n    if index >= len(tokens) or tokens[index].kind != \"[\":\n        raise ValueError(\"expected JSON array\")\n    elements: list[_Element] = []","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/tirth8205/code-review-graph/blob/b58668751ab0c7670c078cf7cbd4d1f5b8e54f81/code_review_graph/uninstall.py#L262-L298","documentation":"Raised by _object_members while walking object members: the token in key position is not a JSON string (e.g. it's a number, brace, or literal). The parser expected '\"key\": value' pairs and found something that cannot be an object key. This indicates structurally invalid or truncated JSONC at the removal target.","triggerScenarios":"Removing a key from an object that contains a bare identifier, number, or nested container in key position, e.g. {2: \"x\"} or a cut-off file ending right after '{'. Also when a previous member's value was mis-skipped due to malformed structure, landing the cursor on a non-string token.","commonSituations":"Hand-edited config with JS-style unquoted keys ({server: ...}); file truncated mid-edit by a crash; trailing garbage after a value; schema migration left an object where a scalar used to be so token alignment shifts.","solutions":["Run the file through a strict JSON validator (after comment-stripping) and fix the malformed object","Quote all object keys — JSONC only permits string keys","If the file is user-owned and possibly hand-edited, verify structure with json.loads on the comment-stripped text before invoking removal","Catch ValueError and skip editing the file, logging it for manual cleanup"],"exampleFix":"// before\n{ mcpServers: { \"x\": {} } }  // unquoted key -> expected JSON object key\n\n// after\n{ \"mcpServers\": { \"x\": {} } }","handlingStrategy":"validation","validationCode":"import json, re\ndef parses_as_json(text: str) -> bool:\n    try:\n        json.loads(re.sub(r\"//[^\\n]*|/\\*.*?\\*/\", \"\", text, flags=re.S))\n        return True\n    except ValueError:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    _remove_jsonc_paths(text, paths)\nexcept ValueError:\n    skip_file_and_log()  # do not rewrite malformed files","preventionTips":["Quote all object keys (JSONC allows comments, not bare identifiers)","Validate config after every hand-edit","Back up configs before automated tools touch them"],"tags":["json","jsonc","syntax","object-keys","validation"],"backgroundTag":"json-parse-error","analyzedSha":"b58668751ab0c7670c078cf7cbd4d1f5b8e54f81","analyzedAt":"2026-08-28T13:19:08.966Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}