How to select ONLY some fields from a YAML file (OpenAPI spec) #2095
Answered
by
mikefarah
alecthegeek
asked this question in
Q&A
-
yq n00b here. I want to extract all the "title", "summary", and "description" fields from an Open API spec document. Like this: yq '.. | select(tag == "!!map") | with_entries(select(.key == "summary" or .key == "description" or .key == "title")) | select(.) ' <(curl -o - https://raw.githubusercontent.com/swagger-api/swagger-petstore/master/src/main/resources/openapi.yaml) However the output is scattered with empty results. For example:
I am sure there must be any easy way to remove the empty entries, but I cannot find it :-(. Thanks |
Beta Was this translation helpful? Give feedback.
Answered by
mikefarah
Jul 21, 2024
Replies: 1 comment 1 reply
-
Not really sure how you want to output the results, but you can use pick to pick particular fields. e.g:
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
alecthegeek
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not really sure how you want to output the results, but you can use pick to pick particular fields.
e.g: