Read and write JSON

Python

Read and write JSON

Use this snippets to read or write json from a file

Read JSON

py

import json def read_json(fname:str): with open(fname) as json_file: return json.load(json_file)

Write JSON

py

import json def write_json(data, fname:str): with open(fname, 'w') as json_file: json.dump(data, json_file, indent=2, ensure_ascii=False)