aboutsummaryrefslogtreecommitdiff
path: root/misc/bin
diff options
context:
space:
mode:
authorYuchen Pei <id@ypei.org>2023-06-20 23:03:45 +1000
committerYuchen Pei <id@ypei.org>2023-06-20 23:03:45 +1000
commit045db0ffe9908cf973a1c8636120b5ab9023299c (patch)
tree4218e8b2a07eb4281b2010bcb5c196e87a634037 /misc/bin
parent880517b4798e201c22e3d318c21b492fe676154b (diff)
Adding vim-vixen
Diffstat (limited to 'misc/bin')
-rwxr-xr-xmisc/bin/merge-json.sh16
1 files changed, 16 insertions, 0 deletions
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"