Skip to content

Missing keys are dropped from [...] inside select/and/or #2782

Description

@johejo

Describe the bug

Collecting a missing key into an array normally produces [null],
but inside a select/and/or condition the missing key is dropped.

Version of yq: 4.53.3
Operating system: mac
Installed via: built from source

Command

yq -n '{} | ([.a] | length)' # 1 (ok)
yq -n '{} | select([.a] | length == 1)' # no output (expected {})
yq -n '{} | (true and ([.a] | length == 1))' # false (expected true)

Actual behaviour

$ yq -n '{} | ([.a] | length)'
1
$ yq -n '{} | select([.a] | length == 1)'
$ yq -n '{} | select([.a] | length == 1)' | wc -c
0
$ yq -n '{} | (true and ([.a] | length == 1))'
false

Expected behaviour

[.a] should be [null] (length 1) everywhere, as it is at the top level (and as in jq):

Additional context

The case in which I actually became aware of this issue was a bit more complex,
But I got advice from Claude and Codex when creating the minimal reproduction case.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions