0
0
Data Analysis Pythondata~15 mins

Exporting to JSON in Data Analysis Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Exporting to JSON
📖 Scenario: You work in a small store that keeps track of product sales. You want to save the sales data in a file so it can be shared with your team easily.
🎯 Goal: Create a Python program that stores sales data in a dictionary, then exports this data to a JSON file.
📋 What You'll Learn
Create a dictionary with product names and their sales numbers
Create a filename variable for the JSON file
Use the json module to export the dictionary to a JSON file
Print a confirmation message after exporting
💡 Why This Matters
🌍 Real World
Exporting data to JSON is common when sharing data between programs or saving data for later use.
💼 Career
Data analysts and scientists often export processed data to JSON files to share with teams or use in web applications.
Progress0 / 4 steps
1
Create the sales data dictionary
Create a dictionary called sales_data with these exact entries: 'Apples': 30, 'Bananas': 45, 'Cherries': 25.
Data Analysis Python
Need a hint?

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

2
Create the JSON filename variable
Create a variable called filename and set it to the string 'sales.json'.
Data Analysis Python
Need a hint?

Use a simple assignment to create the filename variable as a string.

3
Export the dictionary to a JSON file
Import the json module. Then open the file named filename in write mode as file. Use json.dump() to write sales_data to file.
Data Analysis Python
Need a hint?

Use with open(filename, 'w') as file: to open the file and json.dump() to write the dictionary.

4
Print confirmation message
Write a print statement that outputs exactly: "Data exported to sales.json".
Data Analysis Python
Need a hint?

Use print() with the exact message inside quotes.