vik-y
12/12/2015 - 9:23 AM

Generate and read json using python

Generate and read json using python

# Generating json
import json
from pprint import pprint
data = {}
data['key'] = ['value']
data['1']='bak'
json_data = json.dumps(data)

# Output: '{"1": "bak", "key": ["value"]}'




# For reading json file 
import json
from pprint import pprint

with open('data.json') as data_file:    
    data = json.load(data_file)

pprint(data)