#2499·yq

String Interpolation Acts on Unselected Documents

Author: Arc676Created Oct 15, 2025Updated Sep 15, 2026
Labelsbugv4

Describe the bug

When selecting by document index and constructing a string, the ignored documents are still used for string construction, but without any content.

Version of yq: v4.48.1 Operating system: Debian via WSL on Windows Installed via: homebrew

Input Yaml

yaml
# test.yml
name: Alice
---
name: Bob

Command The command you ran:

yq 'select(document_index==0) | "My name is \(.name)"' test.yml

Actual behavior

The string is constructed twice, but because the second document was not selected, there is no content.

yaml
My name is Alice
My name is

Expected behavior

I would have thought that the document that did not fit the select criteria would be dropped entirely.

yaml
My name is Alice

Additional context

This only seems to happen when filtering by document index. If the YAML document contains an array and we select on the array then pipe to a string, no strings are created for the unselected elements.

Perhaps I'm misunderstanding how the pipes or string interpolation are meant to be used. Maybe this is already documented somewhere, but I couldn't find anything. If this is intended behavior, a note in the documentation for interpolation or document filtering would be nice.