In yq expressions are made up of operators and pipes. A context of nodes is passed through the expression and each operation takes the context as input and returns a new context as output. That output is piped in as input for the next operation in the expression. To begin with, the context is set to the first yaml document of the first yaml file (if processing in sequence using eval).

Lets look at a couple of examples.


Given a document like:

- [a]
- "cat"

with an expression:

.[] | length

yq will initially set the context as single node of the entire yaml document, an array of two elements.

- [a]
- "cat"

This gets piped into the splat operator .[] which will split out the context into a collection of two nodes [a] and "cat". Note that this is not a yaml array.

The length operator take no arguments, and will simply return the length of each matching node in the context. So for the context of [a] and "cat", it will return a new context of 1 and 3.

This being the last operation in the expression, the results will be printed out:


Please see the individual operator docs for more information and examples.