Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 657

Combine JSON to YAML list

$
0
0

In a GitLab pipeline job I have multiple JSON files. I need these JSON files as YAML and I would like to have them in the same YAML file as a list. They do not always have the same keys.

I would like the following structure so that I later can iterate over the "mystuff" list with the keys being the filenames (unique)

mystuff:  filename:    content: <whatever>  filename2:    content: <whatever>

I have got this far with yq:

yq eval-all -o=yaml -P '  {"mystuff": (      . as $doc      | {          (filename            | split("/")[-1]            | sub("\\.json$"; "")          ): $doc        }    )  }'"${FILES[@]}" > "$DASH_DIR/_mystuff.yaml"

which gives me:

mystuff:  filename:    content: <whatever>----mystuff:  filename2:    content: <whatever>

I can't figure out how to get it in a single list without changing or merging content or the previous code breaking.

My current solution to this is to run an awk command after the yq command that removes all "----" and every mystuff after the first.


Viewing all articles
Browse latest Browse all 657

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>