Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON File Database

A Java CLI application to add, view, and update user records, persisted locally in a JSON file using the Jackson library.


Requirements

  • Java JDK 8 or higher
  • Maven (to resolve dependencies)

No additional setup needed — data is stored locally in a JSON file.


How to Run

  1. Clone the repository
  2. Add Jackson Databind to your pom.xml:
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.17.1</version>
</dependency>
  1. Run Main.java and follow the prompts

What It Does

  • Add a new user (ID, name, age, occupation, language)
  • Look up a user by ID
  • Update fields of an existing user (skip any field to leave it unchanged)
  • Persists data to src/main/java/database.json automatically
  • Handles missing database file by creating it on first run
  • Safely handles lookups for non-existent IDs

Pros

  • Zero external database setup — just a flat JSON file
  • Human-readable storage, easy to inspect or edit manually
  • TreeMap keeps records sorted by ID automatically
  • Lightweight with minimal dependencies
  • Runs on any device with Java and Maven installed

Limitations

  • No delete — there is no way to remove a user
  • No input validation — entering a string where an integer is expected will crash
  • No duplicate ID check — adding a user with an existing ID silently overwrites it
  • Not thread-safe — concurrent access would corrupt the JSON file
  • Flat schema — the UserRecord model is rigid; adding new fields requires code changes
  • Hardcoded file path — database location is fixed to src/main/java/database.json

Possible Improvements

  • Add a delete-by-ID option
  • Validate input types before parsing (especially age)
  • Check for ID conflicts before inserting and prompt accordingly
  • Add search by name instead of just ID
  • Make the database file path configurable
  • Replace the flat JSON file with SQLite for more robust storage as the project grows

About

A Java CLI application to add, view, and update user records, persisted locally in a JSON file using the Jackson library.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages