{"record":{"id":"4bc43a7782e5594f","repo":"projectdiscovery/nuclei","slug":"could-not-parse-json-s","errorCode":null,"errorMessage":"could not parse json: %s","messagePattern":"could not parse json: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/operators/extractors/compile.go","lineNumber":47,"sourceCode":"\t\tif cached, err := cache.Regex().GetIFPresent(regex); err == nil && cached != nil {\n\t\t\te.regexCompiled = append(e.regexCompiled, cached)\n\t\t\tcontinue\n\t\t}\n\t\tcompiled, err := regexp.Compile(regex)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"could not compile regex: %s\", regex)\n\t\t}\n\t\t_ = cache.Regex().Set(regex, compiled)\n\t\te.regexCompiled = append(e.regexCompiled, compiled)\n\t}\n\tfor i, kval := range e.KVal {\n\t\te.KVal[i] = strings.ToLower(kval)\n\t}\n\n\tfor _, query := range e.JSON {\n\t\tquery, err := gojq.Parse(query)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"could not parse json: %s\", query)\n\t\t}\n\t\tcompiled, err := gojq.Compile(query)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"could not compile json: %s\", query)\n\t\t}\n\t\te.jsonCompiled = append(e.jsonCompiled, compiled)\n\t}\n\n\tfor _, dslExp := range e.DSL {\n\t\tif cached, err := cache.DSL().GetIFPresent(dslExp); err == nil && cached != nil {\n\t\t\te.dslCompiled = append(e.dslCompiled, cached)\n\t\t\tcontinue\n\t\t}\n\t\tcompiled, err := govaluate.NewEvaluableExpressionWithFunctions(dslExp, dsl.HelperFunctions)\n\t\tif err != nil {\n\t\t\treturn &dsl.CompilationError{DslSignature: dslExp, WrappedError: err}\n\t\t}\n\t\t_ = cache.DSL().Set(dslExp, compiled)","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/projectdiscovery/nuclei/blob/265b3a3dec374741614e342f813c10f8b38d2bb7/pkg/operators/extractors/compile.go#L29-L65","documentation":"Template compilation error from Extractor.CompileExtractors (pkg/operators/extractors/compile.go:47). For `type: json` extractors, each `json:` entry must be a valid gojq query. gojq.Parse failing on the syntax produces this error with the offending query text.","triggerScenarios":"A json extractor query like '.a..[' (malformed recursive descent), unbalanced brackets/quotes, or non-jq syntax such as '.a.b(' or JSONPath-style '$.a.b' (jq uses '.a.b', not '$.').","commonSituations":"Using JSONPath ($.store.book[0].title) instead of jq syntax; missing quotes around filter expressions containing special chars; trailing commas or stray parentheses after refactoring a query.","solutions":["Rewrite JSONPath to jq syntax: '$.a.b[0]' becomes '.a.b[0]'","Verify the query with `gojq '.a.b' file.json` or `jq` on sample output before putting it in the template","Balance brackets/quotes and remove stray operators","Validate the template: `nuclei -validate -t template.yaml`"],"exampleFix":"# before\nextractors:\n  - type: json\n    json:\n      - '$.session.token'\n# after\nextractors:\n  - type: json\n    json:\n      - '.session.token'","handlingStrategy":"validation","validationCode":"import \"github.com/itchyny/gojq\"\n\nfor _, q := range ex.JSON {\n\tif _, err := gojq.Parse(q); err != nil {\n\t\treturn fmt.Errorf(\"bad json extractor query %q: %w\", q, err)\n\t}\n}","typeGuard":"func validGojqQuery(q string) bool { _, err := gojq.Parse(q); return err == nil }","tryCatchPattern":"if err := ex.CompileExtractors(); err != nil && strings.Contains(err.Error(), \"could not parse json\") {\n\t// surface the query string plus a jq-syntax hint to the template author\n}","preventionTips":["Use jq syntax (.a.b[0]), never JSONPath ($.a.b)","Prototype each query against a captured response with gojq/jq","Validate templates with -validate in CI"],"tags":["extractor","json","gojq","template","compile-time"],"backgroundTag":null,"analyzedSha":"265b3a3dec374741614e342f813c10f8b38d2bb7","analyzedAt":"2026-08-15T20:05:51.855Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}