How can i check if specific value exist in list with yq . This is my yaml
projects:
   p1:
     - "sample/project/app1"
     - "sample/project/app2"
This is my test code but it return false
cat test.yaml | yq '.projects.p1 | has("sample/project/app1")'
false
Please specify which implementation of yq you are using.
With mikefarah/yq, you could use any_c:
yq '.projects.p1 | any_c(. == "sample/project/app1")' test.yaml
With kislyuk/yq, you could use IN:
yq 'IN(.projects.p1[]; "sample/project/app1")' test.yaml
You cannot check whether array contains a string with has(). Please try instead:
yq < test.yaml '.projects.p1 | index("sample/project/app1") != null'
true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With