Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using yq, delete any key whose scalar value is false

I would like to delete all keys that have a scalar value of false, using https://github.com/mikefarah/yq:

Input

project: false_deletion
fields:
  name:
    numeric: false
    value: John
  age:
    value: 25
    numeric: true
  address:
    value: 123 Main St
    numeric: false

Desired output

project: false_deletion
fields:
  name:
    value: John
  age:
    value: 25
    numeric: true
  address:
    value: 123 Main St

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

yq e 'del(.. | select(. == false))' input

Will del() all those keys where the value is false.

Output:

project: false_deletion
fields:
  name:
    value: John
  age:
    value: 25
    numeric: true
  address:
    value: 123 Main St
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading