import json
# We're opening file for writing operations using with statement, to be sure
# that it would be closed as soon as we would be done with editing.
with open('file.json', 'w') as f:
json.dump({
"list": [1, 2, 3, 4],
"comment": "List of 4 first natural numbers"
}, f, indent=4)
# Lets check its content.
data = json.load(open('file.json'))
print json.dumps(data, indent=4)