Links

Save json file

Tags: #python #json #file #save #data #io
Description: This notebook will demonstrate how to save a json file using Python.
References:

Input

Import libraries

import json

Setup Variables

  • data: a dictionary containing the data to be saved in the json file
  • json_path: json file path
data = {"name": "John Doe", "age": 30, "city": "New York"}
json_path = "data.json"

Model

Save json file

Using the json.dump() function, the data dictionary can be saved to a json file.
with open(json_path, "w") as f:
json.dump(data, f)

Output

Display result

print("The json file has been saved to the current directory.")