yq/pkg/yqlib/doc/Has.md
Mike Farah f7f8bed955 wip
2020-12-27 09:55:21 +11:00

542 B

This is operation that returns true if the key exists in a map (or index in an array), false otherwise.

Has map key

Given a sample.yml file of:

- a: "yes"
  '': null
- a: ~
  '': null
- a:
  '': null
- b: nope
  '': null

then

yq eval '.[] | has("a")' sample.yml

will output

true
true
true
false

Has array index

Given a sample.yml file of:

- []
- [1]
- [1, 2]
- [1, null]
- [1, 2, 3]

then

yq eval '.[] | has(1)' sample.yml

will output

false
false
true
true
true