-
-
Save kitihounel/3979e67de5629f14718d732beaecb911 to your computer and use it in GitHub Desktop.
A JSON minify script written in Python.
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
#!/usr/bin/env python3 | |
"""JSON minifier""" | |
from json import loads, dumps | |
from sys import argv | |
from pathlib import Path | |
def minify(filename): | |
content = '' | |
with open(filename, 'r', 1) as input: | |
content = input.read() | |
obj = loads(content) | |
minified = dumps(obj, separators=(',', ':'), ensure_ascii=False) | |
base = Path(filename).stem | |
name = f'{base}.min.json' | |
with open(name, "w", 1) as f: | |
f.write(minified) | |
f.write('\n') | |
args = argv[1:] | |
for arg in args: | |
minify(arg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment