In my case i was using maven build tool and got this error so had to add below dependency from here like below and error resolved.
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180130</version>
</dependency>
Answer from Alien on Stack OverflowIn my case i was using maven build tool and got this error so had to add below dependency from here like below and error resolved.
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180130</version>
</dependency>
Class org.json.JSONObject is available in json-20131018.jar. You need to download this jar and add this jar to your buildpath.
In order to add external jar to buildpath you can - right click on your project in eclipse - click build path -> configure build path - goto tab libraries - there you will find to add external JAR
This will allow you to include any external jar into your build path.
I have been trying to figure out this issue forever now but I can't seem to see what I'm doing wrong. I am using VSCode and added the json library (json-20220329.jar) to my referenced libraries. When I add the jar file the errors in my main file go away regarding JSONObject and JSONArray. Everything looks fine until I try running the code and it says that the "package org.json does not exist." I was wondering if anyone knew what could be the problem.
CODE: (App.java)
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import org.json.JSONObject;
import org.json.JSONArray;
public class App {
public static void main(String[] args) {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder().uri(URI.create("https://jsonplaceholder.typicode.com/albums")).build();
client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(HttpResponse::body)
.thenAccept(System.out::println)
.join();
}
public static String parse(String responseBody) {
JSONArray albums = new JSONArray(responseBody);
for (int i = 0; i < albums.length(); i++)
{
JSONObject album = albums.getJSONObject(i);
int id = album.getInt("id");
int userID = album.getInt("userId");
String title = album.getString("title");
System.out.println(id + "\t" + title + "\t" + userID);
}
return null;
}
}ERROR:
App.java:8: error: package org.json does not exist
import org.json.JSONObject;
^
App.java:9: error: package org.json does not exist
import org.json.JSONArray;
^
App.java:26: error: cannot find symbol
JSONArray albums = new JSONArray(responseBody);
^
symbol: class JSONArray
location: class App
App.java:26: error: cannot find symbol
JSONArray albums = new JSONArray(responseBody);
^
symbol: class JSONArray
location: class App
App.java:29: error: cannot find symbol
JSONObject album = albums.getJSONObject(i);
^
symbol: class JSONObject
location: class App
5 errorsI'm going to start by saying I'm a complete novice in Java. I've started computer science recently and I've got a project where I have to create a project to represent a server using sockets. The server will has to function as a control a library's book record/register. My professor provided a .json file with the book lists which I have to use.
I tried creating the project on VS Code, but after following these steps:
Downloaded the library from the Maven Repository.
Created a lib folder in your project's root directory and move the json-20230303.jar file to this folder.
My code couldn't import the library and this error appeared every time I tried to use the library:
"src\Gerenciador.java:2: error: package org.json does not exist import org.json.JSONArray;"
After a while I thought it would be easier to import the library on the Ide Eclipse, but after creating the project and adding it via the Build Path option, it still didn't work. Even though the library appeared in the Libraries section in the Java Build Path.
This error: "The type org.json.JSONObject is not accessible" keeps appearing.
I don't know how to fix the problem. I think I'm calling on the library wrong, but I don't know how I should do it. If there is any information missing, let me know and I'll provide it, it's my first time asking for help on a programming forum.
I'm parsing json files using JSONArray and JSONObject but I keep getting the error shown in the title. I've downloaded org.json.jar but I don't know what to do next. Currently, org.json.jar sits in the same path as all of the other java files and classes.
Thanks!
Trying to use JSON to store some objects locally for retrieval later. Can't figure out why I'm unable to import json. Doesn't work in vim, doesn't work in vsCode, doesn't work in Eclipse.
Read online that I may need to download the json .jar and add to my build path? When googling "json download" its only scammy virus websites.
I'm on a Mac.
Edit: Added pictures
https://imgur.com/a/FlKwMIF
Thanks for the help.
Your dependency and import looks correct. Reloading all maven dependencies should resolve the issue. Check this post out: Force Intellij IDEA to reread all maven dependencies
I had the same problem, added org.json dependency and reloaded maven, But still Intellij didn't recognize it.
I tried write following code in module-info.java , then Intellij recognized it:
requires org.json;

