Skip to content

Latest commit

 

History

History
55 lines (31 loc) · 1.8 KB

Python_Save_json_file.md

File metadata and controls

55 lines (31 loc) · 1.8 KB



Template request | Bug report | Generate Data Product

Tags: #python #json #file #save #data #io

Author: Sriniketh Jayasendil

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.")