71. Handling JSON Data
1. Parsing JSON from a String
import json
json_string = '{"name": "Alice", "age": 30}'
parsed_data = json.loads(json_string)
print(parsed_data) # Output: {'name': 'Alice', 'age': 30}2. Converting Python Dictionary to JSON String
import json
data = {"name": "Bob", "age": 25}
json_string = json.dumps(data)
print(json_string) # Output: {"name": "Bob", "age": 25}3. Reading JSON from a File
4. Writing JSON to a File
5. Pretty-Printing JSON Data
6. Converting Python Lists to JSON
7. Handling Non-ASCII Characters in JSON
8. Customizing JSON Serialization
9. Handling JSON with Nested Structures
10. Deserializing JSON with Custom Classes
Last updated