mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 13:48:06 +00:00
Add with_entries
example using filtering
This commit is contained in:
parent
fae2b2643c
commit
ed377a032d
@ -98,3 +98,19 @@ KEY_a: 1
|
||||
KEY_b: 2
|
||||
```
|
||||
|
||||
Using with_entries is also useful whe you want to filter a map. Given a sample.yml file of:
|
||||
```yaml
|
||||
a:
|
||||
b: bird
|
||||
c:
|
||||
d: dog
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq eval 'with_entries(select(.value | has("b")))' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
a:
|
||||
b: bird
|
||||
```
|
@ -52,6 +52,14 @@ var entriesOperatorScenarios = []expressionScenario{
|
||||
"D0, P[], (!!map)::KEY_a: 1\nKEY_b: 2\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "Use with_entries to filter keys",
|
||||
document: `{a: b: "bird", c: d: "dog"}`,
|
||||
expression: `with_entries(.value | has("b"))`,
|
||||
expected: []string{
|
||||
"D0, P[], (!!map)::a:\n b: \"bird\"\n",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestEntriesOperatorScenarios(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user