Created
December 26, 2023 17:40
-
-
Save pkliang/fca8d7cd64eac1f27a78b250b772987f to your computer and use it in GitHub Desktop.
Format json file without whitespaces
This file contains hidden or 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
import json | |
import glob | |
def format_json_compat(file): | |
json_file = open(file) | |
raw_json = json.load(json_file) | |
json_compat = json.dumps(raw_json, indent=None, separators=(',', ':')) | |
print(json_compat) | |
write_file = open(file, 'w') | |
write_file.write(json_compat) | |
# 把json文件和此脚本放在同一目录下,运行此脚本即可 | |
for filename in glob.glob('*.json'): | |
format_json_compat(filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment