blob: be3065774e085b9319cb9feb9c99f81d26a535d4 [file] [log] [blame]
Jan Kundráte950cf72024-09-06 17:46:11 +02001# https://stackoverflow.com/a/53666584/2245623
2# Recursively meld a and b, concatenating arrays and favoring b when there is a conflict
3def meld(a; b):
4 a as $a | b as $b
5 | if ($a|type) == "object" and ($b|type) == "object"
6 then reduce ([$a,$b]|add|keys_unsorted[]) as $k ({};
7 .[$k] = meld( $a[$k]; $b[$k]) )
8 elif ($a|type) == "array" and ($b|type) == "array"
9 then $a+$b
10 elif $b == null then $a
11 else $b
12 end;
13
14reduce inputs as $i (.; meld(.; $i))