{"record":{"id":"15537bf78c51e967","repo":"tomnomnom/gron","slug":"failed-to-parse-s-as-gron-statement","errorCode":null,"errorMessage":"failed to parse '%s' as gron statement","messagePattern":"failed to parse '(.+?)' as gron statement","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"main.go","lineNumber":423,"sourceCode":"\t// Fprintf below\n\tj = bytes.TrimSpace(j)\n\n\tfmt.Fprintf(w, \"%s\\n\", j)\n\n\treturn exitOK, nil\n}\n\n// gronValues prints just the scalar values from some input gron statements\n// without any quotes or anything of that sort; a bit like jq -r\n// e.g. json[0].user.name = \"Sam\"; -> Sam\nfunc gronValues(r io.Reader, w io.Writer, opts int) (int, error) {\n\tscanner := bufio.NewScanner(os.Stdin)\n\n\tfor scanner.Scan() {\n\t\ts := statementFromString(scanner.Text())\n\n\t\tif len(s) == 0 {\n\t\t\treturn exitParseStatements, fmt.Errorf(\"failed to parse '%s' as gron statement\", scanner.Text())\n\t\t}\n\n\t\t// strip off the leading 'json' bare key\n\t\tif s[0].typ == typBare && s[0].text == \"json\" {\n\t\t\ts = s[1:]\n\t\t}\n\n\t\t// strip off the leading dots\n\t\tif s[0].typ == typDot || s[0].typ == typLBrace {\n\t\t\ts = s[1:]\n\t\t}\n\n\t\tfor _, t := range s {\n\t\t\tswitch t.typ {\n\t\t\tcase typString:\n\t\t\t\tvar text string\n\t\t\t\terr := json.Unmarshal([]byte(t.text), &text)\n\t\t\t\tif err != nil {","sourceCodeStart":405,"sourceCodeEnd":441,"githubUrl":"https://github.com/tomnomnom/gron/blob/88a6234ea2d0c487090988182ad9a7cdf6def924/main.go#L405-L441","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","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"],"exampleFix":"// before\n$ echo '{\"a\":1}' | gron -v   // failed to parse '{\"a\":1}' as gron statement\n\n// after\n$ echo '{\"a\":1}' | gron | gron -v","handlingStrategy":"validation","validationCode":"grep -v '^[[:space:]]*$' gron_output | grep -E '^json.*= .*;$' | gron --values","typeGuard":null,"tryCatchPattern":"code, err := gronValues(input, output, opts)\nif err != nil {\n\tif strings.Contains(err.Error(), \"failed to parse\") {\n\t\t// sanitize input lines and retry\n\t}\n\treturn err\n}","preventionTips":["Always run `gron` before `gron --values`","Filter out blank lines and non-statement lines first","Avoid filters that truncate statement lines"],"tags":["go","gron","cli","parsing"],"backgroundTag":"invalid-cli-argument","analyzedSha":"88a6234ea2d0c487090988182ad9a7cdf6def924","analyzedAt":"2026-09-06T11:35:31.658Z","contentChangedAt":"2026-09-06T11:35:31.658Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}