{"record":{"id":"4ecc19d901b2f574","repo":"vitessio/vitess","slug":"cannot-parse-object-key-s","errorCode":null,"errorMessage":"cannot parse object key: %s","messagePattern":"cannot parse object key: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/mysql/json/parser.go","lineNumber":540,"sourceCode":"\t\treturn v, s[1:], nil\n\t}\n\n\to := c.getValue()\n\to.t = TypeObject\n\to.o.reset()\n\tfor {\n\t\tvar err error\n\t\tvar unescape bool\n\t\tkv := o.o.getKV()\n\n\t\t// Parse key.\n\t\ts = skipWS(s)\n\t\tif len(s) == 0 || s[0] != '\"' {\n\t\t\treturn nil, s, errors.New(`cannot find opening '\"\" for object key`)\n\t\t}\n\t\tkv.k, s, unescape, err = parseRawKey(s[1:])\n\t\tif err != nil {\n\t\t\treturn nil, s, fmt.Errorf(\"cannot parse object key: %s\", err)\n\t\t}\n\t\tif unescape {\n\t\t\tkv.k = unescapeStringBestEffort(kv.k)\n\t\t}\n\t\ts = skipWS(s)\n\t\tif len(s) == 0 || s[0] != ':' {\n\t\t\treturn nil, s, errors.New(\"missing ':' after object key\")\n\t\t}\n\t\ts = s[1:]\n\n\t\t// Parse value\n\t\ts = skipWS(s)\n\t\tkv.v, s, err = parseValue(s, c, depth)\n\t\tif err != nil {\n\t\t\treturn nil, s, fmt.Errorf(\"cannot parse object value: %s\", err)\n\t\t}\n\t\ts = skipWS(s)\n\t\tif len(s) == 0 {","sourceCodeStart":522,"sourceCodeEnd":558,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/mysql/json/parser.go#L522-L558","documentation":"While parsing a JSON object, the key portion (which must start with a double quote and parse via parseRawKey) failed; the underlying error is wrapped as 'cannot parse object key:'. The key is either missing its opening quote or contains a malformed/unterminated escape sequence.","triggerScenarios":"Parsing `{name: \"x\"}` (unquoted key), `{\"name: 1}` (unterminated key string), or a key with a dangling backslash like `{\"a\\\\\": 1}` with an invalid escape.","commonSituations":"Hand-written JSON with unquoted keys (JavaScript object literal style); truncated strings; code that escapes keys incorrectly.","solutions":["Quote all object keys with double quotes and ensure they are terminated","Escape backslashes/quotes in keys properly (e.g. `\\\\\"` not `\"`)","Validate the JSON before parsing to pinpoint the malformed key"],"exampleFix":"// before\nv, err := mysql.ParseJSON(\"{name: 1}\")\n// after\nv, err := mysql.ParseJSON(`{\"name\": 1}`)","handlingStrategy":"validation","validationCode":"func keyIsQuoted(doc string) bool {\n\treturn !regexp.MustCompile(`\\{\\s*[A-Za-z_]`).MatchString(doc)\n}","typeGuard":null,"tryCatchPattern":"v, err := mysql.ParseJSON(input)\nif err != nil {\n\tif strings.Contains(err.Error(), \"cannot parse object key\") {\n\t\t// locate the unquoted/unterminated key and repair or reject\n\t}\n\treturn err\n}","preventionTips":["Always double-quote object keys — JS object literals are not JSON","Escape backslashes and quotes inside keys via encoding/json.Marshal on the key string","Reject documents at the boundary with json.Valid before passing to mysql"],"tags":["json","parsing","object"],"backgroundTag":"invalid-json-syntax","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}