Writing JSON to a File


PHOTO EMBED

Tue Dec 08 2020 20:22:03 GMT+0000 (UTC)

Saved by @aymanelya #python

import json

data = {}
data['people'] = []
data['people'].append({
    'name': 'Scott',
    'website': 'stackabuse.com',
    'from': 'Nebraska'
})
data['people'].append({
    'name': 'Larry',
    'website': 'google.com',
    'from': 'Michigan'
})

with open('data.txt', 'w') as outfile:
    json.dump(data, outfile)
content_copyCOPY

https://stackabuse.com/reading-and-writing-json-to-a-file-in-python/