tomnomnom/gron · error
failed to parse '%s' as gron statement
Error message
failed to parse '%s' as gron statement
What it means
gronValues (the `--values`/`-v` action) parses each input line with statementFromString. If tokenization yields zero tokens, the line is not a recognizable gron statement and the action aborts with "failed to parse '%s' as gron statement" and exit code exitParseStatements.
Source
Thrown at main.go:423
// Fprintf below
j = bytes.TrimSpace(j)
fmt.Fprintf(w, "%s\n", j)
return exitOK, nil
}
// gronValues prints just the scalar values from some input gron statements
// without any quotes or anything of that sort; a bit like jq -r
// e.g. json[0].user.name = "Sam"; -> Sam
func gronValues(r io.Reader, w io.Writer, opts int) (int, error) {
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
s := statementFromString(scanner.Text())
if len(s) == 0 {
return exitParseStatements, fmt.Errorf("failed to parse '%s' as gron statement", scanner.Text())
}
// strip off the leading 'json' bare key
if s[0].typ == typBare && s[0].text == "json" {
s = s[1:]
}
// strip off the leading dots
if s[0].typ == typDot || s[0].typ == typLBrace {
s = s[1:]
}
for _, t := range s {
switch t.typ {
case typString:
var text string
err := json.Unmarshal([]byte(t.text), &text)
if err != nil {View on GitHub (pinned to 88a6234ea2)
Solutions
- Ensure input to `gron --values` is gron-generated statement output, not raw JSON
- Strip blank/empty lines before piping: grep -v '^[[:space:]]*$'
- Sanitize any filter (grep/awk) output so it preserves complete `json... = value;` lines
Example fix
// before
$ echo '{"a":1}' | gron -v // failed to parse '{"a":1}' as gron statement
// after
$ echo '{"a":1}' | gron | gron -v Defensive patterns
Strategy: validation
Validate before calling
grep -v '^[[:space:]]*$' gron_output | grep -E '^json.*= .*;$' | gron --values
Try / catch
code, err := gronValues(input, output, opts)
if err != nil {
if strings.Contains(err.Error(), "failed to parse") {
// sanitize input lines and retry
}
return err
} Prevention
- Always run `gron` before `gron --values`
- Filter out blank lines and non-statement lines first
- Avoid filters that truncate statement lines
When it happens
Trigger: `gron --values` given blank lines or lines without assignment structure (no `key = value;` form), e.g. raw JSON, log lines, or empty input lines from trailing newlines.
Common situations: Piping gron output through filters that insert blank lines or headers; forgetting to run `gron` first and passing JSON directly to `gron -v`; concatenating outputs with stray whitespace.
Understand the failure class
Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- invalid JSON layout
- invalid statement
- statement has no value
- failed to form statements: %s
- non-assignment statement
AI-assisted analysis of tomnomnom/gron@88a6234ea2 (2026-09-06).
Data as JSON: /api/errors/15537bf78c51e967.
Report an issue: GitHub.