DS160123 How to crate json fule in VS code and how to convert dict in json file

Date;- 17/03/2023
I have a doubt to create a json file in Visual Studio and how to convert dictionary in json file in Visual Studio.?


Import the json module.
Use the json.dump() method to convert the dictionary to a JSON string and write it to a file.
For example:

import json

dictionary = {“name”: “John”, “age”: 30, “city”: “New York”}

with open(“data.json”, “w”) as file:
json.dump(dictionary, file)

If you are using write mode (w) here, a json file named data will be created to your default path of your VS code.

1 Like