ZachSun commited on
Commit
03a77f1
·
verified ·
1 Parent(s): e83cc1e

Upload merge_json.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. merge_json.py +23 -0
merge_json.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import json
3
+
4
+ def merge_json_files(folder_path, output_file):
5
+ merged_data = []
6
+
7
+ # Iterate over all files in the folder
8
+ for filename in os.listdir(folder_path):
9
+ if filename.endswith(".jsonl"):
10
+ file_path = os.path.join(folder_path, filename)
11
+ print(file_path)
12
+ with open(file_path) as f:
13
+ data=[json.loads(line) for line in f]
14
+ merged_data.extend(data)
15
+ # Write the merged data to the output file
16
+ with open(output_file, "w", encoding="utf-8") as out_f:
17
+ json.dump(merged_data, out_f, indent=4, ensure_ascii=False)
18
+
19
+ print(f"Merged {len(merged_data)} entries into {output_file}")
20
+
21
+
22
+ # Example usage:
23
+ merge_json_files("/home/gs4288/visual_pruning_kl/data/playground", "/home/gs4288/visual_pruning_kl/data/playground/merged.json")