Skip to content
Latchkey

yq eval-all: Process All Documents Together

yq eval-all reads every input document into memory before evaluating, so the expression can see and combine them all.

Merging a base manifest with an overlay, or reducing many documents into one, needs all documents in scope simultaneously. That is the job eval-all (alias ea) exists for.

What it does

Unlike eval, which runs once per document, yq eval-all collects all documents from all inputs first, then evaluates the expression with the full set available. It is required for cross-document operations like merging two files.

Common usage

Terminal
# merge two files, later overrides earlier
yq eval-all '. as $item ireduce ({}; . * $item)' base.yaml overlay.yaml
# the common shorthand for "merge all docs"
yq ea '. *= load("overlay.yaml")' base.yaml
# select document index 1 of a multi-doc file
yq ea 'select(documentIndex == 1)' multi.yaml

eval-all uses

ExpressionEffect
eval-all (alias ea)Load all documents before evaluating
. as $i ireduce ({}; . * $i)Deep-merge every document into one
select(documentIndex == 0)Keep only the first document
select(fileIndex == 1)Keep documents from the second file
... comments=""Strip comments while merging

In CI

Layering a per-environment overlay onto a base values file is a classic eval-all merge: yq ea '. as $i ireduce ({}; . * $i)' base.yaml prod.yaml > merged.yaml. Document order matters: later inputs win with the * merge operator.

Common errors in CI

Using plain eval (or no subcommand) for a merge produces wrong output because each document is processed alone; switch to eval-all. "Error: cannot index array with ..." in a merge usually means one input is a list and the other a map. Python yq has no eval-all; multi-document merges there require jq -s style slurping instead, so this command erroring is another wrong-implementation signal.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →