0
0
Pythonprogramming~15 mins

Serializing and deserializing JSON in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Serializing and deserializing JSON
📖 Scenario: You are working on a simple contact list app. You want to save the contacts to a file and later read them back.
🎯 Goal: Learn how to convert a Python dictionary to a JSON string (serialize) and then convert it back from JSON string to a Python dictionary (deserialize).
📋 What You'll Learn
Create a Python dictionary with exact contact details
Create a JSON string from the dictionary using json.dumps()
Convert the JSON string back to a dictionary using json.loads()
Print the final dictionary to verify it matches the original
💡 Why This Matters
🌍 Real World
Many apps save data in JSON format because it is easy to share and read by different programs.
💼 Career
Understanding JSON serialization and deserialization is essential for backend development, APIs, and data exchange between systems.
Progress0 / 4 steps
1
Create the contacts dictionary
Create a dictionary called contacts with these exact entries: 'Alice': 'alice@example.com', 'Bob': 'bob@example.com', 'Charlie': 'charlie@example.com'
Python
Need a hint?

Use curly braces {} to create a dictionary and separate keys and values with colons.

2
Import the json module
Add the line import json at the top of your code to use JSON functions
Python
Need a hint?

Use import json to access JSON functions in Python.

3
Serialize the dictionary to JSON string
Create a variable called contacts_json and set it to the JSON string of contacts using json.dumps(contacts)
Python
Need a hint?

Use json.dumps() to convert a dictionary to a JSON string.

4
Deserialize the JSON string and print
Create a variable called contacts_loaded and set it to the dictionary obtained by deserializing contacts_json using json.loads(contacts_json). Then print contacts_loaded
Python
Need a hint?

Use json.loads() to convert JSON string back to a dictionary. Then use print() to show the result.