tomnomnom/gron · error

invalid quoted key `%s`

Error message

invalid quoted key `%s`

What it means

During statement un-groning, a token classified as a quoted key (typQuotedKey) fails json.Unmarshal into a string, meaning the token's text is not a valid JSON quoted string. This fires on malformed input like unterminated or badly escaped quotes.

Source

Thrown at ungron.go:414

	case t.typ == typBare:
		val, err := ungronTokens(ts[1:])
		if err != nil {
			return nil, err
		}
		out := make(map[string]interface{})
		out[t.text] = val
		return out, nil

	case t.typ == typQuotedKey:
		val, err := ungronTokens(ts[1:])
		if err != nil {
			return nil, err
		}
		key := ""
		err = json.Unmarshal([]byte(t.text), &key)
		if err != nil {
			return nil, fmt.Errorf("invalid quoted key `%s`", t.text)
		}

		out := make(map[string]interface{})
		out[key] = val
		return out, nil

	case t.typ == typNumericKey:
		key, err := strconv.Atoi(t.text)
		if err != nil {
			return nil, fmt.Errorf("invalid integer key `%s`", t.text)
		}

		val, err := ungronTokens(ts[1:])
		if err != nil {
			return nil, err
		}

		// There needs to be at least key + 1 space in the array

View on GitHub (pinned to 88a6234ea2)

Solutions

  1. Fix the quoted key in the input so it is a valid JSON string (matching quotes, proper escaping)
  2. Check the input statement around the reported token for stray or missing quote characters
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at ungron.go:414 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of tomnomnom/gron@88a6234ea2 (2026-09-06). Data as JSON: /api/errors/7b639803983c68db. Report an issue: GitHub.