-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmerge_jsons.py
46 lines (40 loc) · 1.24 KB
/
merge_jsons.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import json
import argparse
import os
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"-ja", "--json-a",
type=str,
help="First json"
)
parser.add_argument(
"-jb", "--json-b",
type=str,
help="Second json to be merged into the first (and overwriting existing entries)"
)
parser.add_argument(
"-jo", "--json-output",
type=str,
help="Output json file name"
)
parser.add_argument(
"-o", "--output",
type=str,
default="output/jsons/merged",
help="Folder where the merged output json will be written to"
)
return parser.parse_args()
if __name__ == "__main__":
args = parse_args()
if not os.path.exists(os.path.join(args.output)):
os.makedirs(os.path.join(args.output))
with open(args.json_a) as json_file:
json_a = json.load(json_file)
with open(args.json_b) as json_file:
json_b = json.load(json_file)
json_a["corrections"].extend(json_b["corrections"])
new_path = os.path.join(args.output, args.json_output)
with open(new_path, "w") as json_file:
json.dump(json_a, json_file, indent=4)
os.system(f"gzip < {new_path} > {new_path}.gz")