what is json.dump in python code example
Example 1: json dumps python
# How to encode JSON as a string
import json
print(json.dumps({'a': 1, 'b': 2}) # '{ "a": 1, "b": 2 }'
print(json.dumps({'b': 1, 'a': 2}, sort_keys=True, indent=4))
# {
# "a": 2,
# "b": 1
# }
Example 2: python json dump
import json
with open("data_file.json", "w") as write_file:
json.dump(data, write_file)