mirror of
https://github.com/taigrr/yq
synced 2025-01-18 04:53:17 -08:00
Added has operator
This commit is contained in:
44
pkg/yqlib/doc/Has.md
Normal file
44
pkg/yqlib/doc/Has.md
Normal file
@@ -0,0 +1,44 @@
|
||||
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:
|
||||
```yaml
|
||||
- a: yes
|
||||
- a: ~
|
||||
- a:
|
||||
- b: nope
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq eval '.[] | has("a")' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
true
|
||||
true
|
||||
true
|
||||
false
|
||||
```
|
||||
|
||||
## Has array index
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
- []
|
||||
- [1]
|
||||
- [1, 2]
|
||||
- [1, null]
|
||||
- [1, 2, 3]
|
||||
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq eval '.[] | has(1)' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
false
|
||||
false
|
||||
true
|
||||
true
|
||||
true
|
||||
```
|
||||
|
||||
1
pkg/yqlib/doc/headers/Has.md
Normal file
1
pkg/yqlib/doc/headers/Has.md
Normal file
@@ -0,0 +1 @@
|
||||
This is operation that returns true if the key exists in a map (or index in an array), false otherwise.
|
||||
Reference in New Issue
Block a user