Parse JSON Files in Python: Quick Guide

In Python, you can use the built-in json module to parse and extract JSON files. Here is a simple example:

import json

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

# 提取数据
name = data['name']
age = data['age']

# 打印数据
print(f"Name: {name}")
print(f"Age: {age}")

In this example, we start by using the json.load() method to load data from a JSON file, then we can access and extract the desired data using keys. Finally, we use the print() function to display the extracted data.

bannerAds