JSON (JavaScript Object Notation) is a commonly used data exchange format, which is widely used in web development, API calls and data storage. Python provides a built-in json module that can easily handle JSON data. This article will introduce how to use Python to process JSON data, including JSON parsing, generation and modification operations, and provide corresponding source code examples.
- Parse JSON data
To parse JSON data, you first need to convert the JSON string into a Python object. The json module provides the loads() function, which can parse JSON strings into Python objects. Here's a simple example:
import json
json_str = '{"name": "John", "age": 30, "city": "New York"}'
data = json.loads(json_str)
print(data["name"