Skip to content

Convert object array to string array with comments #1902

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

You must be logged in to vote

TLDR:

yq 'with(.[]; . line_comment= .id | . = .name)

Explanation:

  • .[] matches every array element
  • with(.[] ; ...), sets the inner context to each array element, like a for loop
  • . line_comment= .id sets the line comment of the current element to be the id value
  • . = .name) sets the current element value to the name value.

Replies: 1 comment 1 reply

Comment options

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

Answer selected by alinjie
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