{"record":{"id":"baa12824f0197035","repo":"vitessio/vitess","slug":"expected-or-in-object-got-q","errorCode":null,"errorMessage":"expected ',' or '}' in object, got %q","messagePattern":"expected ',' or '\\}' in object, got %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/mysql/json/marshal.go","lineNumber":276,"sourceCode":"\t}\n}\n\nfunc (w *sqlWriter) writeObject(depth int) error {\n\tw.buf.WriteString(\"JSON_OBJECT(\")\n\tfirst := true\n\tfor {\n\t\tw.skipWhitespace()\n\t\tif w.pos >= len(w.data) {\n\t\t\treturn errors.New(\"unexpected end of JSON input in object\")\n\t\t}\n\t\tif w.data[w.pos] == '}' {\n\t\t\tw.pos++\n\t\t\tw.buf.WriteByte(')')\n\t\t\treturn nil\n\t\t}\n\t\tif !first {\n\t\t\tif w.data[w.pos] != ',' {\n\t\t\t\treturn fmt.Errorf(\"expected ',' or '}' in object, got %q\", w.data[w.pos])\n\t\t\t}\n\t\t\tw.pos++\n\t\t\tw.buf.WriteString(\", \")\n\t\t\tw.skipWhitespace()\n\t\t}\n\t\tfirst = false\n\n\t\t// Key (always a string).\n\t\tif w.pos >= len(w.data) || w.data[w.pos] != '\"' {\n\t\t\treturn errors.New(\"expected string key in JSON object\")\n\t\t}\n\t\tw.buf.WriteString(\"_utf8mb4\")\n\t\tif err := w.writeStringContent(); err != nil {\n\t\t\treturn fmt.Errorf(\"reading JSON object key: %w\", err)\n\t\t}\n\t\tw.buf.WriteString(\", \")\n\n\t\t// Colon separator.","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/mysql/json/marshal.go#L258-L294","documentation":"While writing a JSON object to SQL form, writeObject expects each member after the first to be separated by a comma and the object eventually closed with '}'. If, after writing a key/value pair, the next non-whitespace byte is neither ',' nor '}', the writer aborts with this error. It indicates malformed object syntax — a missing separator, a stray token, or a truncated object.","triggerScenarios":"AppendMarshalSQL on input where an object member is followed by something other than ',' or '}' — e.g. `{\"a\": 1 \"b\": 2}` (missing comma), `{\"a\": 1; }` (wrong separator), or truncated input like `{\"a\": 1` followed by end of data hitting an unexpected byte.","commonSituations":"Hand-built JSON strings missing commas between fields; template-generated JSON with conditional fields that drop separators; log/trace payloads truncated mid-object; mixing serialization formats (e.g. semicolons).","solutions":["Fix the JSON so object members are separated by commas: {\"a\": 1, \"b\": 2}","Validate the input with encoding/json.Valid before marshaling to catch the malformation early","Check template/conditional serialization logic that may omit the separator between fields","Inspect for truncated input — if the document is cut off, fix the producer rather than patching the string"],"exampleFix":"// before\nraw := []byte(`{\"a\": 1 \"b\": 2}`)\nout, err := json.AppendMarshalSQL(nil, raw)\n// after\nraw := []byte(`{\"a\": 1, \"b\": 2}`)\nout, err := json.AppendMarshalSQL(nil, raw)","handlingStrategy":"validation","validationCode":"raw := []byte(input)\nif !json.Valid(raw) {\n    return fmt.Errorf(\"input is not valid JSON: missing separators or truncated object\")\n}","typeGuard":null,"tryCatchPattern":"out, err := json.AppendMarshalSQL(nil, raw)\nif err != nil {\n    if strings.Contains(err.Error(), \"expected ',' or '}'\") {\n        return fmt.Errorf(\"malformed JSON object near: %w\", err)\n    }\n    return err\n}","preventionTips":["Build objects with an encoding library (encoding/json.Marshal) instead of string concatenation","In template generators, join fields with an explicit comma separator between items","Check for truncation — verify input ends with the expected closing brace","Validate with encoding/json.Valid before conversion"],"tags":["go","json","parsing","syntax-error"],"backgroundTag":"malformed-json-input","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}