A command-line Python tool for creating, viewing, and editing data stored in a JSON file. It loads a JSON file into a Python dictionary, lets you add, update, or delete entries from a menu, and saves the changes back to disk.
- Save starter data: create
data.jsonwith a starter profile (asks before overwriting) - Load data: read the file and show which keys it contains
- View data: print the full contents, neatly formatted
- Add or update: add a new key and value, or change an existing one
- Delete data: remove a key and its value
- Starts safely on a first run, even if
data.jsondoesn't exist yet
- Python 3.6 or newer
- No external packages; it uses only Python's built-in
jsonmodule
-
Clone the repository:
git clone https://github.com/MichaelTM0/json-data-manager.git cd json-data-manager -
Run the program:
python jsondata.py
-
Choose option 1 to create
data.jsonwith the starter data, or option 4 to start adding your own.
==================================================
1. Save starter data (overwrites file)
2. Load data
3. View data
4. Add or update data
5. Delete data
6. Exit
Please enter a number (1-6):
Example output for option 3 (View data):
{
"name": "Michael",
"age": 26,
"skills": [
"Python",
"AWS",
"GitHub"
]
}Every change follows the same three steps:
- Load:
load_data()opensdata.jsonand usesjson.loadto turn it into a Python dictionary. - Change: the dictionary is edited in Python (adding, updating, or deleting a key).
- Save:
save_data()usesjson.dumpto write the updated dictionary back todata.json.
The file is only open while it's being read or written. All edits happen on the dictionary in memory, and with blocks close the file automatically.
- Convert number input to integers (right now, everything typed is saved as text)
- Add items to list values, like adding a new skill to
skills - Support multiple profiles instead of one
- Back up the file before overwriting it
- Reading and writing JSON files with
json.loadandjson.dump - How Python dictionaries map to JSON
- Writing reusable
load_dataandsave_datahelpers instead of repeating file code - Using
withblocks so files close automatically - When to use
try/except(unexpected errors) vsif/else(expected choices)
Michael Murchie
- GitHub: @MichaelTM0
- LinkedIn: michael-murchie