Welcome, Gunters! In the OASIS, artifacts like the Zemeckis Cube or Orb of Osuvox are priceless treasures, and you need a high-tech way to catalog them safely. Enter JSON—a powerful format for storing structured data, like a digital inventory scroll that’s easy to read and update. In this lesson, you’ll learn to read and write JSON files using Python’s json module, turning raw artifact data into organized records. You’ll open JSON files to display artifacts, add new finds, and save them securely, all while dodging IOI’s prying eyes. These skills will power up your OASIS terminal and prepare you for your final mission: a full-fledged artifact scanner project!
🧠 Understand JSON as a structured data format and its advantages over plain text.
📖 Read JSON files using json.load() to load artifact data into Python.
✍️ Write JSON files using json.dump() to save or update artifact records.
🔄 Combine JSON with file handling (open(), with) and error handling for robust programs.
🎮 Apply JSON skills in an OASIS-themed task to catalog Ready Player One artifacts.
🚀 Prepare for the final project by mastering structured data management.
We're going to stay in the theme of Ready Player One, and visit the OASIS!! Get Ready!
JSON (JavaScript Object Notation) is like a Gunter’s high-tech inventory system in the OASIS—it organizes data (like artifact names and descriptions) into neat key-value pairs that are easy to read and update.
Unlike plain text files (e.g., “item:description”), JSON supports complex structures, like lists and nested details, making it perfect for storing game items, user profiles, or mission logs.
Reading JSON lets your programs load this data into Python dictionaries or lists, while writing JSON saves your changes back to a file, keeping your OASIS data safe between runs.
JSON is a standard format used in games, web apps, and APIs, giving your programs real-world power.
It’s easier to parse than splitting text strings, saving you coding time.
It’s flexible, letting you store rich data (e.g., an artifact’s name, description, and owner) without messy formats.
JSON is a lightweight format for storing structured data, looking like a Python dictionary or list but saved as text in a file.
It uses key-value pairs (like a dictionary) and supports lists, numbers, strings, and nested objects.
In the OASIS, JSON is like a digital scroll that lists artifacts with their details, making it easy to read or update without manual parsing.
Organizes data into dictionaries ({}) or lists ([]) with keys and values.
Looks like Python code but uses strict rules (e.g., double quotes, no trailing commas).
This is what an example json file looks like. And, within it, we can store...
Python’s built-in json module lets you read JSON files into Python objects (dictionaries/lists) and write Python objects back to JSON files. It works with open() and with, just like text files, and builds on your file-handling skills from CH09-01 and CH09-02.
For the following activities, you'll need to do is create the json file below.
Using the json file created above, this is how we load it, and then print out each of the items and descriptions
Load the json file
Create a function to read the json file and print the information out nicely
Loads the existing list of dictionaries from the file
Adds a new dictionary to that list
Writes everything back to the file using json.dump()
Load the json file
Create a functions to:
Prompt the user to enter in a new item and description
Append it to the current json which was read in
Write it as a new file
Convert Python → JSON string
Think of it like packing your stuff into a box.
You have a Python object like a dictionary ({"player": "Parzival", "level": 42}).
json.dumps() turns that Python object into a JSON string — a plain text version that can be stored, shared, or sent to another program.
Convert JSON string → Python object
Now you’re unpacking the box to use the stuff inside.
You have a JSON-formatted string (text that looks like a dictionary).
json.loads() converts the string back into a real Python object you can use in your code.
Build a program that manages a small OASIS artifact database using a .json file. You will:
Create a JSON file with 5 artifacts
Load and display artifact data
Add new artifacts
Save changes back to the file
Manually create a file named artifacts.json in the same folder as their Python program with the following content:
✅ 1. Display All Artifacts
Load artifacts.json using json.load()
Print each artifact in a formatted way:
✅ 2. Add a New Artifact
Prompt user for:
Artifact name
Description
Where it was used
Append a new dictionary to the list of artifacts
✅ 3. Save and Exit
Use json.dump() to overwrite artifacts.json with the updated list
Use indent=4 and ensure_ascii=False for readability
Exit the loop
Search Artifact:
Add a menu option “4: Search Artifact” that prompts for an item name and displays its description (case-insensitive).
Example: Search “zemeckis” shows “Zemeckis Cube: Rewinds time by 60 seconds”.
Delete Artifact:
Add a menu option “5: Delete Artifact” that prompts for an item name, removes it from the JSON list, and updates the file.
Confirm with “Are you sure? (y/n)”.
The json methods have parameters that can be loaded in to each call. You can see examples of what's available, as well as some usage below
In this example, you can see how we use multiple parameters for our json write (dump)