Skip to content

Commit

Permalink
Add JSON validator function to remove specified keys from JSON strings
Browse files Browse the repository at this point in the history
  • Loading branch information
sealbell committed Jun 8, 2024
1 parent 99900e1 commit a56b59d
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion ai_commons/file_processing/json_validator.py
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
# JSON validator module
# Json validator module

import json

def remove_keys_from_json(json_string, keys_to_remove):
# 解析JSON字符串为列表
data_list = json.loads(json_string)

# 遍历列表中的每个字典
for data in data_list:
for key_list in keys_to_remove:
for key in key_list:
if key in data:
del data[key]

# 将列表转换回JSON字符串
return json.dumps(data_list, ensure_ascii=False)

0 comments on commit a56b59d

Please sign in to comment.