Answers for "python dump json into file"

12

python json save to file

with open('output.json', 'w') as outfile:
    json.dump(data, outfile)
Posted by: Guest on January-18-2021
5

write json to file python

import json

with open('data.txt') as json_file:
    data = json.load(json_file)
    for p in data['people']:
        print('Name: ' + p['name'])
        print('Website: ' + p['website'])
        print('From: ' + p['from'])
        print('')
Posted by: Guest on November-29-2019
0

save json dump to file python

On a modern system (i.e. Python 3 and UTF-8 support), you can write a nice file with:

import json
with open('data.json', 'w', encoding='utf-8') as f:
    json.dump(data, f, ensure_ascii=False, indent=4)
Posted by: Guest on April-23-2021
-3

write json dump to file python

import json
import numpy as np

class NpEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, np.integer):
            return int(obj)
        elif isinstance(obj, np.floating):
            return float(obj)
        elif isinstance(obj, np.ndarray):
            return obj.tolist()
        else:
            return super(NpEncoder, self).default(obj)

# Your codes .... 
json.dumps(data, cls=NpEncoder)
Posted by: Guest on December-01-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language