{"record":{"id":"7304eea2cd53c775","repo":"antonmedv/fx","slug":"comments-are-not-allowed-in-strict-mode","errorCode":null,"errorMessage":"Comments are not allowed in strict mode","messagePattern":"Comments are not allowed in strict mode","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/jsonx/json.go","lineNumber":587,"sourceCode":"\tpanic(fmt.Sprintf(\"Unexpected character %q\", p.char))\n}\n\nfunc isEndOfValue(ch byte) bool {\n\treturn isWhitespace(ch) || ch == ',' || ch == '}' || ch == ']' || ch == 0 // 0 is EOF\n}\n\nfunc isWhitespace(ch byte) bool {\n\treturn ch == ' ' || ch == '\\t' || ch == '\\n' || ch == '\\r'\n}\n\nfunc (p *JsonParser) skipWhitespace() {\n\tfor {\n\t\tswitch p.char {\n\t\tcase ' ', '\\t', '\\n', '\\r':\n\t\t\tp.next()\n\t\tcase '/':\n\t\t\tif p.strict {\n\t\t\t\tpanic(\"Comments are not allowed in strict mode\")\n\t\t\t}\n\t\t\tp.skipComment()\n\t\tdefault:\n\t\t\treturn\n\t\t}\n\t}\n}\n\nfunc (p *JsonParser) skipComment() {\n\tp.next()\n\tswitch p.char {\n\tcase '/':\n\t\tfor p.char != '\\n' && p.char != 0 {\n\t\t\tp.next()\n\t\t}\n\tcase '*':\n\t\tfor {\n\t\t\tp.next()","sourceCodeStart":569,"sourceCodeEnd":605,"githubUrl":"https://github.com/antonmedv/fx/blob/4f31cd3a0c5d66f1b4290a2719bab14a5cee8ebe/internal/jsonx/json.go#L569-L605","documentation":"The lenient parser of this library allows // and /* */ comments while skipping whitespace, but strict mode (standard JSON) forbids them. When skipWhitespace encounters '/' and p.strict is true, it panics with this message. It means the document contains a comment, which is not part of the JSON specification.","triggerScenarios":"Calling Parse with strict=true on JSON containing // line comments or /* block comments */ anywhere whitespace is legal (between elements, after {, etc.).","commonSituations":"Hand-edited config files (VS Code jsonc, tsconfig.json-style files), .jsonc files saved as .json, tools that emit annotated JSON.","solutions":["Remove all // and /* */ comments from the input before parsing.","Parse with strict=false if the parser instance is under your control, since the lenient mode supports comments.","Strip comments programmatically with a JSONC stripper before calling Parse.","Rename/rehandle the file as JSONC and use a JSONC-aware tool."],"exampleFix":"// before (input.json)\n{\n  // retry count\n  \"retries\": 3\n}\n// after\n{\n  \"retries\": 3\n}","handlingStrategy":"validation","validationCode":"if strings.Contains(string(data), \"//\") || strings.Contains(string(data), \"/*\") {\n    if strictRequired {\n        return errors.New(\"comments present but strict JSON required; strip them first\")\n    }\n    data = stripJSONCComments(data)\n}","typeGuard":null,"tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        if strings.Contains(fmt.Sprint(r), \"Comments are not allowed\") {\n            err = errors.New(\"file is JSONC; strip comments or use lenient mode\")\n        }\n    }\n}()","preventionTips":["Keep comments in .jsonc files, not .json.","Run a JSONC-to-JSON stripper on hand-edited config files before parsing.","Detect comment patterns in pre-validation and route to a lenient parser.","Educate editors of config files that JSON has no comments."],"tags":["json","strict-mode","comments","jsonc"],"backgroundTag":"comments-not-allowed-in-json","analyzedSha":"4f31cd3a0c5d66f1b4290a2719bab14a5cee8ebe","analyzedAt":"2026-09-02T02:17:47.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}