Output JSON-Code in readable and sorted form so it’s diffable

This code will read in a JSON file and print it out again in readable form and keys in sorted order – making two files diffable!

Usage: jsonsort.py

#!/usr/bin/env python

import json
import sys

file = sys.argv[1]

with open(file, 'r') as f:
  read_data = f.read()
f.closed

print json.dumps(json.loads(read_data),sort_keys=True, indent=4, separators=(',', ': '))