-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JSON validator function to remove specified keys from JSON strings
- Loading branch information
Showing
1 changed file
with
17 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |