{"record":{"id":"7688a19340d79fb7","repo":"projectdiscovery/nuclei","slug":"could-not-compile-json-s","errorCode":null,"errorMessage":"could not compile json: %s","messagePattern":"could not compile json: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/operators/extractors/compile.go","lineNumber":51,"sourceCode":"\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)\n\t\te.dslCompiled = append(e.dslCompiled, compiled)\n\t}\n\n\tif e.CaseInsensitive {","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/projectdiscovery/nuclei/blob/265b3a3dec374741614e342f813c10f8b38d2bb7/pkg/operators/extractors/compile.go#L33-L69","documentation":"Template compilation error from Extractor.CompileExtractors (pkg/operators/extractors/compile.go:51). The json extractor's gojq query parses successfully but fails the gojq.Compile step, which type-checks the AST (function arity, unknown built-ins, invalid option usage).","triggerScenarios":"Queries calling a jq builtin gojq does not implement, wrong function arity (e.g. 'ltrimstr()' with no args or 'ascii_downcase(1)'), or invalid use of operators that parse but do not compile.","commonSituations":"Templates tested against a full jq build using rarely supported builtins or flags; version drift where the template was written for a newer gojq than the embedded nuclei version ships.","solutions":["Simplify the query to well-supported core builtins (.x | .[0], //, | tostring, | tonumber, ltrimstr/1 etc.) and check arity","Run the exact query through `gojq` at the version nuclei vendors to confirm it compiles","Move complex transformation into a DSL extractor (type: dsl) where helper functions are richer","Re-validate the template after upgrading nuclei/gojq versions"],"exampleFix":"# before (invalid arity)\njson:\n  - '.token | ltrimstr()'\n# after\njson:\n  - '.token | ltrimstr(\"Bearer \")'","handlingStrategy":"validation","validationCode":"for _, q := range ex.JSON {\n\tast, err := gojq.Parse(q)\n\tif err != nil { return err }\n\tif _, err := gojq.Compile(ast); err != nil {\n\t\treturn fmt.Errorf(\"query %q compiles-parse but fails gojq.Compile: %w\", q, err)\n\t}\n}","typeGuard":"func compilableGojq(q string) bool { ast, err := gojq.Parse(q); if err != nil { return false }; _, err = gojq.Compile(ast); return err == nil }","tryCatchPattern":"if err := ex.CompileExtractors(); err != nil && strings.Contains(err.Error(), \"could not compile json\") {\n\t// report unsupported builtin/arity; suggest DSL extractor for heavy transforms\n}","preventionTips":["Stick to core jq builtins and correct arity","Pin/track the gojq version vendored by your nuclei version when writing advanced queries","Move complex shaping to type: dsl extractors"],"tags":["extractor","json","gojq","template","compile-time"],"backgroundTag":null,"analyzedSha":"265b3a3dec374741614e342f813c10f8b38d2bb7","analyzedAt":"2026-08-15T20:05:51.855Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}