Skip to content

Commit 32c172a

Browse files
committed
Used json5.load() in data.json.read(), added missing .write()
1 parent 0ac0f22 commit 32c172a

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

  • remove-json-keys/src/remove_json_keys/lib/data

remove-json-keys/src/remove_json_keys/lib/data/json.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import json, os, re
2+
import json5
23
from . import file
34

45
def read(file_path):
5-
if not os.path.exists(file_path):
6-
return {}
76
with open(file_path, 'r', encoding='utf-8') as file:
8-
return json.load(file)
7+
return json5.load(file)
98

109
def remove_keys(json_dir, keys):
1110
keys_removed, keys_skipped, files_processed_cnt = [], [], 0
@@ -32,3 +31,8 @@ def remove_keys(json_dir, keys):
3231
files_processed_cnt += 1
3332

3433
return keys_removed, keys_skipped, files_processed_cnt
34+
35+
def write(src_data, target_path):
36+
os.makedirs(os.path.dirname(target_path), exist_ok=True)
37+
with open(target_path, 'w', encoding='utf-8') as file:
38+
json.dump(src_data, file, indent=2, ensure_ascii=False)

0 commit comments

Comments
 (0)