tomnomnom/gron · error
invalid value `%s`
Error message
invalid value `%s`
What it means
In ungronTokens, value tokens are decoded with encoding/json (with UseNumber). If json.Decode fails on the token's text, the token is not a valid JSON value and ungronTokens returns "invalid value `%s`" containing the offending text.
Source
Thrown at ungron.go:393
}
t := ts[0]
switch {
case t.isPunct():
// Skip the token
val, err := ungronTokens(ts[1:])
if err != nil {
return nil, err
}
return val, nil
case t.isValue():
var val interface{}
d := json.NewDecoder(strings.NewReader(t.text))
d.UseNumber()
err := d.Decode(&val)
if err != nil {
return nil, fmt.Errorf("invalid value `%s`", t.text)
}
return val, nil
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 := ""View on GitHub (pinned to 88a6234ea2)
Solutions
- Quote string values with double quotes: json.a = "hello";
- Fix malformed numbers (no leading zeros beyond 0, no double dots, no NaN/Infinity)
- Regenerate input via `gron` rather than writing statements by hand
- Pre-validate each RHS value with json.Valid([]byte(value)) before ungron
Example fix
// before json.a = 'hello'; // after json.a = "hello";
Defensive patterns
Strategy: validation
Validate before calling
value := `"hello"` // RHS text from the statement
if !json.Valid([]byte(value)) {
// invalid JSON value; fix quoting/number before ungron
} Type guard
func isJSONValue(text string) bool {
return json.Valid([]byte(text))
} Try / catch
v, err := ungronTokens(ts)
if err != nil {
if strings.HasPrefix(err.Error(), "invalid value `") {
// quote strings / fix numeric literals, then retry
}
return err
} Prevention
- Double-quote all string values in hand-written statements
- Avoid NaN/Infinity and leading-zero numbers
- Prefer generating statements with gron over hand-writing them
When it happens
Trigger: `gron --ungron` on statements whose value tokens are not valid JSON — e.g. bare numbers like `json.a = 007;`, malformed numbers (`1.2.3`), unquoted bare words in value position, or text corrupted by shell/quoting.
Common situations: Hand-written gron statements where strings were not quoted; output mangled by sed removing quotes; gron statements produced by other tools with non-JSON literals (NaN, Infinity, single-quoted strings).
Related errors
- invalid JSON layout
- invalid statement
- failed to form statements: %s
- non-assignment statement
- statement has no value
AI-assisted analysis of tomnomnom/gron@88a6234ea2 (2026-09-06).
Data as JSON: /api/errors/fccdb88c06717bdb.
Report an issue: GitHub.