How use yq to transform list format

86 Views Asked by At

Given following yaml format

value:
 - 1
 - 2
 - 3

How to use yq to output

value: [ 1, 2, 3]
1

There are 1 best solutions below

0
mike.f On

You can change the style of the array by running:

yq '.value style="flow"' data.yaml

This sets the 'style' metadata property of the 'value' node to "flow". This actually made me realise I didn't document how style works for arrays, I've updated the documentation to include more examples:

https://mikefarah.gitbook.io/yq/operators/style#set-flow-quote-style

Disclaimer: I wrote yq