Skip to navigation

Troubleshoot jq Paths

View as MarkdownOpen in Claude

Every path in a definition is a jq expression. The errors on this page name the exact expression that failed, so search your definition for that string. For the other kinds of errors, refer to Troubleshoot Definitions.

Find the Field That Failed

An error from the validator names the expression and the field that holds it. The field is in the notation of the Go type, from the Spec root of the definition. In the following output, the expression .spec.x[ is the replicasPath of the first child component:

INVALID: my-workload.yaml
failed to parse JQ expression '.spec.x[' at 'Spec.StructureDefinition.ChildComponents[0].ScaleDefinition.ReplicasPath': unexpected EOF
error: 1 finding(s) in my-workload.yaml

jq Path Errors

A path can fail at two times. The validator parses every path when it validates the definition. The library compiles and runs a path when it evaluates the path against a real object.

Error messageWhenCauseFix
failed to parse JQ expression '<expr>' at '<path>': ...ValidationThe expression is not syntactically valid jq.Fix the syntax. Common causes are unbalanced brackets or quotes, a missing leading ., and the wrong quote style around ["key"].
failed to compile JQ expression '<expr>': ...EvaluationThe expression parses but cannot compile, for example because it references an unknown function.Use only standard jq builtins. Check the function names and the number of arguments.
JQ execution error for expression '<expr>': ...EvaluationThe expression compiled but failed while it ran against real data, often because of a null traversal.Make the path null-safe. Supply defaults with //, for example (.status.active // 0) or .spec.parallelism // 1.

Constructs That a Definition Does Not Allow

The validator also checks every expression statically before the library runs it. It walks the parsed jq syntax tree, and it rejects anything that changes data or can produce unbounded output:

  • Assignment and update operators: =, |=, +=, -=, *=, /=, %=, and //=.
  • The del function.
  • The recursive descent operator ...
  • The unbounded functions range, paths, recurse, walk, and repeat.
Error messageCauseFix
JQ expression '<expr>' at '<path>' failed validation: modifying operator '<op>' is not allowedThe expression uses an assignment or update operator.The paths of a definition read state, and they never write it. Rewrite the expression so that it only reads.
JQ expression '<expr>' at '<path>' failed validation: del function is not allowedThe expression deletes fields.Read the value. Do not change it.
JQ expression '<expr>' at '<path>' failed validation: recursive descent operator '..' is not allowedThe expression uses .., which walks the whole document.Spell out the absolute path to the field instead.
JQ expression '<expr>' at '<path>' failed validation: function '<name>' may produce excessive output and is not allowedThe expression uses an unbounded function: range, paths, recurse, walk, or repeat.Use a bounded expression that addresses the fields directly.

Test an Expression

Test an expression against a real workload manifest with the jq command before you put it in a definition. The following command reproduces what Workload Map evaluates:

kubectl get <resource> -o json | jq '<expr>'

The jq playground works as well, without leaving the browser.

To check all the paths of a definition against a real workload, use karta-verify. It reports an expression that is valid but extracts nothing. For more information, refer to Define a Workload Type.

Next Steps

  • To learn which object each path is evaluated against, refer to Paths in the Workload Definition Spec.
  • To fix a structure error, refer to Troubleshoot Definitions.