JQ
action: jq.filter runs a jq program on JSON and writes each result to stdout. The jq engine is built in, so the host needs no jq binary.
Use it for jq programs that filter, reshape, or aggregate. To pick one value by path or convert CSV and YAML, Data is simpler.
Basic Usage
steps:
- id: active_emails
action: jq.filter
with:
filter: '.users[] | select(.active) | .email'
raw: true
data:
users:
- {email: alice@example.com, active: true}
- {email: bob@example.com, active: false}
- {email: carol@example.com, active: true}stdout:
alice@example.com
carol@example.comEach result goes on its own line. Without raw: true, results are JSON, indented with four spaces, so these would print with quotes.
Provide the Input
Set one of data or input:
| Form | Example | Reads |
|---|---|---|
| YAML value | data: {items: [1, 5, 10]} | The value, as JSON. |
| JSON string | data: '{"name": "Alice"}' | The string, parsed as JSON. |
file:// string | data: file://report.json | The file, parsed as JSON. |
input | input: report.json | The file, parsed as JSON. |
A relative input or file:// path resolves against the step working directory, which is a fresh per-run directory unless working_dir is set. To filter a file an earlier step wrote, pass its path through an output:
steps:
- id: export
run: |
path="$DAG_RUN_WORK_DIR/items.json"
printf '%s\n' '{"items": [{"name": "a"}, {"name": "b"}]}' > "$path"
printf 'json_path=%s\n' "$path" >> "$DAGU_OUTPUT_FILE"
outputs:
- name: json_path
- id: names
action: jq.filter
with:
input: ${steps.export.outputs.json_path}
filter: '.items[].name'
raw: truePass Values Into the Filter
args binds jq variables. Each key becomes $key in the filter, and values keep their YAML type:
params:
- min_price: "4"
steps:
- id: cheap_fruit
action: jq.filter
with:
filter: '.items[] | select(.price > ($min | tonumber)) | .name'
raw: true
args:
min: ${params.min_price}
data:
items:
- {name: apple, price: 5}
- {name: pear, price: 3}stdout: apple.
- A reference such as
${params.min_price}resolves to a string. Convert it withtonumberbefore comparing it to a JSON number. A literalmin: 4stays a number. - A key may start with one
$:minand$minbind the same variable, and giving both fails. - To pass a literal
$NAME, escape it:text: '\$NAME'.
Keep the Filter Literal
Without args, Dagu resolves references in the filter before jq runs, including environment variables written as $NAME. A filter of '"hello $NAME"' with NAME: world in the DAG env prints "hello world".
With args, even args: {}, the whole filter is passed to jq unchanged. Use args whenever the filter has jq variables of its own, and pass workflow values through it.
Reshape and Aggregate
steps:
- id: sales_by_category
action: jq.filter
with:
filter: |
group_by(.category)
| map({category: .[0].category, total: (map(.amount) | add), count: length})
data:
- {category: Electronics, amount: 299.99}
- {category: Clothing, amount: 49.99}
- {category: Electronics, amount: 199.99}The step prints one JSON array. Capture it with output: NAME, or publish fields from it with object-form output.
Configuration
| Field | Required | Default | Description |
|---|---|---|---|
filter | Yes | jq program. | |
data | One of data, input | Inline YAML value, JSON string, or file:// path. | |
input | One of data, input | Path to a JSON file. | |
raw | No | false | Write strings without quotes, like jq -r. |
args | No | None | Map of jq variable name to value. Its presence keeps the filter literal. |
Output
- Without
raw: each result as JSON, indented with four spaces, followed by a newline. - With
raw: strings without quotes, numbers and booleans as text, andnullas an empty line. Objects and arrays are written as compact JSON. haltstops the program and the step succeeds.halt_errorfails the step.
Errors
Validation rejects a missing filter, both data and input, an empty data string, and an unknown field.
These fail when the step runs:
- Neither
datanorinputis set. - The input file cannot be read, or the input is not valid JSON.
- The filter does not parse or compile, including a variable that
argsdoes not define. argsbinds the same variable twice, such asminand$min.- The filter raises an error while it runs, such as indexing a string.

