2 """A command line utility to merge two JSON files.
4 This is a python program that merges two JSON files into a single one. The
5 intended use for this is to combine generated 'compile_commands.json' files
6 created by CMake when performing an LLVM runtime build.
15 parser
= argparse
.ArgumentParser(description
=__doc__
)
19 help="The output file to write JSON data to",
24 "json_files", type=str, nargs
="+", help="Input JSON files to merge"
26 args
= parser
.parse_args()
30 for json_file
in args
.json_files
:
32 with
open(json_file
, "r") as f
:
34 merged_data
.extend(data
)
35 except (IOError, json
.JSONDecodeError
) as e
:
38 # Deduplicate by converting each entry to a tuple of sorted key-value pairs
39 unique_data
= list({json
.dumps(entry
, sort_keys
=True) for entry
in merged_data
})
40 unique_data
= [json
.loads(entry
) for entry
in unique_data
]
42 with
open(args
.o
, "w") as f
:
43 json
.dump(unique_data
, f
, indent
=2)
46 if __name__
== "__main__":