Import Error Using JSON in Java

Question: How do I properly use and manipulate JSON in Java?

Background: Hey all, I am trying to manipulate a JSON file to store user data in a Java program. I have created a default JSON file with the default state of the save file and will have individual programs create copies of it which my save system will write/read to. I have gotten “package does not exist” errors when trying to use the json-simple-1.1.1.jar file. The exact errors differ based on what set of imports that I try.

Relevant Code Snippets

The Java File ( imports I have tried:

//I first tried these imports
// import org.json.simple.JSONArray; 
// import org.json.simple.JSONObject; 
// import org.json.simple.parser.*; 

//Then, I tried these imports
// import json.simple.JSONAray;
// import json.simple.JSONObject;
// import json.simple.parser.JSONParser;

//Then, I tried these imports (and all of them failed, not just bc I didn't include JSONParser)
import org.json.JSONArray;
import org.json.JSONObject;

Uses of JSON scattered throughout

    File jsonFile = new File("userProgress.json");
    File defaultFile = new File("defaultUserProgress.json");
    Object obj = new JSONParser().parse(new FileReader("userProgress.json"));  

    JSONObject userProgressJSON = (JSONObject) obj;
    JSONArray courses = (JSONArray) userProgressJSON.get("courses");

json-simple-1.1.1.jar is a file under target/dependency, is mentioned in pom.xml, and I tried manually adding it to the .classpath file. The first two were done automatically and the latter I did after suggestion by replit AI.

pom.xml dependency of json-simple-1.1.1.jar:


.classpath classentry of json-simple-1.1.1.jar:

  <classpathentry kind="lib" path="target/dependency/json-simple-1.1.1.jar"/>

Thank you in advance for any and all help, this is my first time using JSON files! Please let me know if you need any more details!

I can’t reproduce this problem with a skeletal repl:

The import should be org.json.simple.JSONArray

edit: If you can, you should use GSON instead.