git @ Cat's Eye Technologies Dipple / master python / pretty-json-inplace.py
master

Tree @master (Download .tar.gz)

pretty-json-inplace.py @masterraw · history · blame

# SPDX-FileCopyrightText: Chris Pressey, the original author of this work, has dedicated it to the public domain.
# For more information, please refer to <https://unlicense.org/>
# SPDX-License-Identifier: Unlicense

import os
import json
import sys

filename = sys.argv[1]

with open(filename, 'r') as f:
    data = json.loads(f.read())

with open(filename, 'w') as f:
    f.write(json.dumps(data, indent=4, sort_keys=True))