Skip to content

Latest commit

 

History

History
18 lines (15 loc) · 330 Bytes

write-json-file.md

File metadata and controls

18 lines (15 loc) · 330 Bytes
title description author tags
Write JSON File
Writes a dictionary to a JSON file.
e3nviction
json,file,write
import json

def write_json(filepath, data):
    with open(filepath, 'w') as file:
        json.dump(data, file, indent=4)

# Usage:
data = {'name': 'John', 'age': 30}
write_json('data.json', data)