QuickSnip LogoA light blue logo with a thunderbolt in bracketsQuickSnip

Write JSON File

Writes a dictionary to a JSON file.

  • json
  • file
  • write

Code

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)