How to load a JSON file in Python?

You can use the json module to load a JSON file in Python. Here is an example code:

import json

# 读取 JSON 文件
with open('data.json', 'r') as file:
    data = json.load(file)

# 输出数据
print(data)

In the code above, the json.load() function is used to load a JSON file and convert it into a Python object. You can open the JSON file using the open() function, load the data using json.load(), and manipulate the data.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds