Here’s how to write JSON to a file with Python:

import json

data = {
    "key1": "value1",
    "key2": "value2",
    "key3": "value3",
}

formatted_data = json.dumps(data, indent=4)

with open("./data.json", "w") as f:
    f.write(formatted_data)

# Notes
# "indent=4" is optional, but formats the data nicely.
# "w" is a file mode that opens the file for writing only.