{"record":{"id":"40e2e30dbc89be4c","repo":"tomnomnom/gron","slug":"failed-to-convert-statements-to-json","errorCode":null,"errorMessage":"failed to convert statements to JSON","messagePattern":"failed to convert statements to JSON","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"main.go","lineNumber":385,"sourceCode":"\n\t// If there's only one top level key and it's \"json\", make that the top level thing\n\tmergedMap, ok := merged.(map[string]interface{})\n\tif ok {\n\t\tif len(mergedMap) == 1 {\n\t\t\tif _, exists := mergedMap[\"json\"]; exists {\n\t\t\t\tmerged = mergedMap[\"json\"]\n\t\t\t}\n\t\t}\n\t}\n\n\t// Marshal the output into JSON to display to the user\n\tout := &bytes.Buffer{}\n\tenc := json.NewEncoder(out)\n\tenc.SetIndent(\"\", \"  \")\n\tenc.SetEscapeHTML(false)\n\terr = enc.Encode(merged)\n\tif err != nil {\n\t\treturn exitJSONEncode, errors.Wrap(err, \"failed to convert statements to JSON\")\n\t}\n\tj := out.Bytes()\n\n\t// If the output isn't monochrome, add color to the JSON\n\tif opts&optMonochrome == 0 {\n\t\tc, err := colorizeJSON(j)\n\n\t\t// If we failed to colorize the JSON for whatever reason,\n\t\t// we'll just fall back to monochrome output, otherwise\n\t\t// replace the monochrome JSON with glorious technicolor\n\t\tif err == nil {\n\t\t\tj = c\n\t\t}\n\t}\n\n\t// For whatever reason, the monochrome version of the JSON\n\t// has a trailing newline character, but the colorized version\n\t// does not. Strip the whitespace so that neither has the newline","sourceCodeStart":367,"sourceCodeEnd":403,"githubUrl":"https://github.com/tomnomnom/gron/blob/88a6234ea2d0c487090988182ad9a7cdf6def924/main.go#L367-L403","documentation":"After merging all parsed statements, the ungron function's json.Encoder.Encode failed to serialize the merged result for display. Since the merged value comes from successfully parsed JSON tokens, this is practically a hard failure (exit code exitJSONEncode) and indicates an unencodable value slipped into the merged tree.","triggerScenarios":"Thrown at main.go:385 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the merged structure for values JSON cannot encode (e.g. channels, funcs, or unsupported types added upstream)","Check the underlying wrapped error to identify which value failed to encode"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"88a6234ea2d0c487090988182ad9a7cdf6def924","analyzedAt":"2026-09-06T11:35:31.658Z","contentChangedAt":"2026-09-06T11:35:31.658Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}