From 045db0ffe9908cf973a1c8636120b5ab9023299c Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Tue, 20 Jun 2023 23:03:45 +1000 Subject: Adding vim-vixen --- misc/bin/merge-json.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 misc/bin/merge-json.sh (limited to 'misc/bin') diff --git a/misc/bin/merge-json.sh b/misc/bin/merge-json.sh new file mode 100755 index 0000000..871176a --- /dev/null +++ b/misc/bin/merge-json.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# Merge two json objects +# https://e.printstacktrace.blog/merging-json-files-recursively-in-the-command-line/ + +jq -s 'def deepmerge(a;b): + reduce b[] as $item (a; + reduce ($item | keys_unsorted[]) as $key (.; + $item[$key] as $val | ($val | type) as $type | .[$key] = if ($type == "object") then + deepmerge({}; [if .[$key] == null then {} else .[$key] end, $val]) + elif ($type == "array") then + (.[$key] + $val | unique) + else + $val + end) + ); + deepmerge({}; .)' "$1" "$2" -- cgit v1.2.3