lynn-twinkl commited on
Commit ·
d2a43bc
1
Parent(s): 469baff
json function to merge two json training files
Browse files- ner-training/merge_json.py +25 -0
ner-training/merge_json.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import sys
|
| 3 |
+
|
| 4 |
+
original_json_path = sys.argv[1]
|
| 5 |
+
additional_json_path = sys.argv[2]
|
| 6 |
+
|
| 7 |
+
with open(additional_json_path, 'r') as source_file:
|
| 8 |
+
source_data = json.load(source_file)
|
| 9 |
+
|
| 10 |
+
# Load data from target.json
|
| 11 |
+
with open(original_json_path, 'r') as target_file:
|
| 12 |
+
target_data = json.load(target_file)
|
| 13 |
+
|
| 14 |
+
# Ensure both source_data and target_data are lists
|
| 15 |
+
if isinstance(source_data, list) and isinstance(target_data, list):
|
| 16 |
+
# Append records from source_data to target_data
|
| 17 |
+
target_data.extend(source_data)
|
| 18 |
+
else:
|
| 19 |
+
print("The JSON data must be a list of records in both files.")
|
| 20 |
+
|
| 21 |
+
# Write updated data back to target.json
|
| 22 |
+
with open(original_json_path, 'w') as target_file:
|
| 23 |
+
json.dump(target_data, target_file, indent=4)
|
| 24 |
+
|
| 25 |
+
print("Records have been appended successfully.")
|