vitessio/vitess · error

cannot parse object key: %s

Error message

cannot parse object key: %s

What it means

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.

Source

Thrown at go/mysql/json/parser.go:540

		return v, s[1:], nil
	}

	o := c.getValue()
	o.t = TypeObject
	o.o.reset()
	for {
		var err error
		var unescape bool
		kv := o.o.getKV()

		// Parse key.
		s = skipWS(s)
		if len(s) == 0 || s[0] != '"' {
			return nil, s, errors.New(`cannot find opening '"" for object key`)
		}
		kv.k, s, unescape, err = parseRawKey(s[1:])
		if err != nil {
			return nil, s, fmt.Errorf("cannot parse object key: %s", err)
		}
		if unescape {
			kv.k = unescapeStringBestEffort(kv.k)
		}
		s = skipWS(s)
		if len(s) == 0 || s[0] != ':' {
			return nil, s, errors.New("missing ':' after object key")
		}
		s = s[1:]

		// Parse value
		s = skipWS(s)
		kv.v, s, err = parseValue(s, c, depth)
		if err != nil {
			return nil, s, fmt.Errorf("cannot parse object value: %s", err)
		}
		s = skipWS(s)
		if len(s) == 0 {

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Quote all object keys with double quotes and ensure they are terminated
  2. Escape backslashes/quotes in keys properly (e.g. `\\"` not `"`)
  3. Validate the JSON before parsing to pinpoint the malformed key

Example fix

// before
v, err := mysql.ParseJSON("{name: 1}")
// after
v, err := mysql.ParseJSON(`{"name": 1}`)
Defensive patterns

Strategy: validation

Validate before calling

func keyIsQuoted(doc string) bool {
	return !regexp.MustCompile(`\{\s*[A-Za-z_]`).MatchString(doc)
}

Try / catch

v, err := mysql.ParseJSON(input)
if err != nil {
	if strings.Contains(err.Error(), "cannot parse object key") {
		// locate the unquoted/unterminated key and repair or reject
	}
	return err
}

Prevention

When it happens

Trigger: Parsing `{name: "x"}` (unquoted key), `{"name: 1}` (unterminated key string), or a key with a dangling backslash like `{"a\\": 1}` with an invalid escape.

Common situations: Hand-written JSON with unquoted keys (JavaScript object literal style); truncated strings; code that escapes keys incorrectly.

Related errors


AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01). Data as JSON: /api/errors/4ecc19d901b2f574. Report an issue: GitHub.