{"record":{"id":"4cda78a70ca7d3b6","repo":"gchq/CyberChef","slug":"invalid-jpath-expression-err-message","errorCode":null,"errorMessage":"Invalid JPath expression: ${err.message}","messagePattern":"Invalid JPath expression: (.+?)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/JPathExpression.mjs","lineNumber":63,"sourceCode":"     * @returns {string}\n     */\n    run(input, args) {\n        const [query, delimiter] = args;\n        let results, jsonObj;\n\n        try {\n            jsonObj = JSON.parse(input);\n        } catch (err) {\n            throw new OperationError(`Invalid input JSON: ${err.message}`);\n        }\n\n        try {\n            results = JSONPath({\n                path: query,\n                json: jsonObj\n            });\n        } catch (err) {\n            throw new OperationError(`Invalid JPath expression: ${err.message}`);\n        }\n\n        return results.map(result => JSON.stringify(result)).join(delimiter);\n    }\n\n}\n\nexport default JPathExpression;\n","sourceCodeStart":45,"sourceCodeEnd":72,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/JPathExpression.mjs#L45-L72","documentation":"Thrown when the JSONPath query passed to the JPath operation is syntactically invalid or unsupported by the underlying JSONPath library. The query string is handed verbatim to JSONPath({path, json}); if the engine rejects the path syntax it throws, and that message is surfaced.","triggerScenarios":"Malformed path: '$.store.book[' (unclosed bracket), 'store.book' (missing leading $ root), a filter with a syntax error like '?(@.price >)', or recursive-descent '..' used where the library does not support it. Mixing jq syntax ('.foo') into a JSONPath field also triggers it.","commonSituations":"Translating between jq and JSONPath syntax without adjusting grammar. Copying an expression from a different JSONPath implementation (there are several dialects). Typos in bracket notation. Using script/filter extensions the linked build does not support.","solutions":["Verify the root token: JSONPath expressions start with '$' (or '@' in filters).","Validate bracket/parenthesis balancing and filter syntax '?(...)' before running.","Test the expression in a JSONPath playground using the same library CyberChef bundles (jsonpath-plus).","If migrating from jq, rewrite the expression in JSONPath grammar, not jq grammar."],"exampleFix":"// before: jq-style expression passed to JSONPath\nchef.JPathExpression(json, { query: '.store.book[].title' });\n// after: valid JSONPath\nchef.JPathExpression(json, { query: '$.store.book[*].title' });","handlingStrategy":"try-catch","validationCode":"function looksLikeJsonPath(q) {\n  return typeof q === 'string' && /^[@$]/.test(q) &&\n    (q.match(/\\[/g)||[]).length === (q.match(/\\]/g)||[]).length &&\n    (q.match(/\\(/g)||[]).length === (q.match(/\\)/g)||[]).length;\n}","typeGuard":"function isJsonPathExpression(q) {\n  return typeof q === 'string' && q.length > 0 && /^[@$.*\\[\\]()]/.test(q);\n}","tryCatchPattern":"try {\n  return chef.JPathExpression(json, { query });\n} catch (e) {\n  if (/Invalid JPath expression/.test(e.message)) {\n    throw new Error(`JSONPath syntax error - check root token '$' and brackets: ${e.message}`);\n  }\n  throw e;\n}","preventionTips":["Start every JSONPath with '$' (or '@' inside filters).","Balance brackets and parentheses before running.","Remember JSONPath and jq are different grammars - do not mix them."],"tags":["jpath","jsonpath","query","validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}