Skip to content
Discussion options

You must be logged in to vote

You may need to modify this a little, but hopefully you get the gist:

yq '. as $d1 | load("file2.yaml") as $d2 | 
   ($d1 | .paths | keys | .[]) as $i ireduce($d2; 
   .paths[$i] = .paths[$i] // $d1.paths[$i])' file1.yaml

Explanation:
High level, this works by reducing the path keys from file1 into file2, where each path we either use file2 if present, file1 otherwise.

  • '. as $d1 | load("file2.yaml") as $d2 Load the files into $d1 and $d1
  • ($d1 | .paths | keys | .[]) as $i ireduce($d2 Reduce the paths in $d1 into $d2
  • .paths[$i] = .paths[$i] // $d1.paths[$i] Every path element in $d1, update the path entry in $d2. Using the alternative operator // this will use the existing $d2 path if it's…

Replies: 1 comment 1 reply

Comment options

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

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