MaykaGR commited on
Commit
5bef9ed
·
verified ·
1 Parent(s): b408b10

Upload json_util.py

Browse files
Files changed (1) hide show
  1. app/json_util.py +26 -0
app/json_util.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def merge_json_recursive(base, update):
2
+ """Recursively merge two JSON-like objects.
3
+ - Dictionaries are merged recursively
4
+ - Lists are concatenated
5
+ - Other types are overwritten by the update value
6
+
7
+ Args:
8
+ base: Base JSON-like object
9
+ update: Update JSON-like object to merge into base
10
+
11
+ Returns:
12
+ Merged JSON-like object
13
+ """
14
+ if not isinstance(base, dict) or not isinstance(update, dict):
15
+ if isinstance(base, list) and isinstance(update, list):
16
+ return base + update
17
+ return update
18
+
19
+ merged = base.copy()
20
+ for key, value in update.items():
21
+ if key in merged:
22
+ merged[key] = merge_json_recursive(merged[key], value)
23
+ else:
24
+ merged[key] = value
25
+
26
+ return merged