You can use Python module json to write JSON data to a file as shown in the below example –
1 2 3 4 5 6 7 8 9 |
import json ## Python 2 and 3 with open('data.json', 'w') as f: json.dump(data, f) ## Python 3 or greater with open('data.json', 'w', encoding='utf-8') as f: json.dump(data, f, ensure_ascii=False, indent=4) |