Yq: How can I search elements in an array?

Created on 25 Jun 2020  路  3Comments  路  Source: mikefarah/yq

Hi,
If I understand the doc correctly, I should be able to search the following array for an app called app2

apps:
- name: app1
  slackChannel: my-team
- name: app2
  autoSync: true

But the following doesn't work: yq read myfile.yaml "apps[*](.name==app2)".

Am I missing something?

I am using the the docker image for mikefarah/yq:3.3.2

bug

Most helpful comment

@yfried : I guess the [*] will match all the array elements of the parent. I think you need to use the Search by children nodes feature to get the index of the element containing your required string app2 i.e. as

yq read myfile.yaml 'apps.(name==app2)'

All 3 comments

@yfried : I guess the [*] will match all the array elements of the parent. I think you need to use the Search by children nodes feature to get the index of the element containing your required string app2 i.e. as

yq read myfile.yaml 'apps.(name==app2)'

Hi @inianv this doesn't work. I'm getting empty output. Any other ideas?

@inianv's solution is correct, and it works for me...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

il1yaz picture il1yaz  路  3Comments

curiositycasualty picture curiositycasualty  路  5Comments

cdaguerre picture cdaguerre  路  4Comments

ykfq picture ykfq  路  8Comments

pcrocker-pivotal picture pcrocker-pivotal  路  3Comments