Skip to content

Return string value directly, or reduce list to string if value is a list #1592

Answered by mikefarah
manuelgrabowski asked this question in Q&A
Discussion options

You must be logged in to vote

Easiest way I can think of solving that is to add the .pm to an empty array. If its a string, you'll have an array with a single string. If it's an array of strings, then it will simple be an array concatenation, and you end up with the array of strings. From there, you can join the string if desired:

./yq '.stages[].groups[] | select(.name | test("(?i)'"exe"'")) | {.name: [] + .pm}'

yields:

"Pipeline Execution":
  - Jackie Porter

with join:

./yq '.stages[].groups[] | select(.name | test("(?i)'"exe"'")) | {.name: [] + .pm | join(", ")}' 

yields:

"Pipeline Execution": Jackie Porter

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@manuelgrabowski
Comment options

Answer selected by manuelgrabowski
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants