I assume that you have already downloaded the JSON library. If not, you can download it from here: Maven repo
Go to File -> Project Structure...
Then click on the Library tab on the left-hand side. You can add or remove any libraries. 
I assume that you have already downloaded the JSON library. If not, you can download it from here: Maven repo
Go to File -> Project Structure...
Then click on the Library tab on the left-hand side. You can add or remove any libraries. 
if you tried all the download links for the Json.jar and its probably not working you can check this link out
after the link loads, search in the table where you can find "file" at the right of it you will see different kinds of file types. Select jar and wait for it to download.
you can now add the downloaded json.jar file in your Intelij.
open your intelij IDE press CTRL + ALT + SHIFT + S
just by the left of the dialog select modules then from the tabs choose dependencies then hit the + choose JARs or Directories, a dialog is gonna pop up prompting you to select the file path or directory where you have your json.jar. in most cases the json.jar is located in the downloads folder for PC users since it was downloaded. So, select the directory that have your json.jar file, find the json.jar in the directory. Then, hit enter and apply then wait for it to sync.
java - Getting - package org.json does not exist - unable to use JSONArray / JSONObject - Stack Overflow
java - Idea Intellij: Dependency org.json:json:20180813 not found, can't import org.json library in maven - Stack Overflow
Intellij IDEA can't find a class in successfully imported Maven dependency - Stack Overflow
I have a little problem
Videos
I'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.
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;
cloud1's answer helped me out:
Try pressing 'Reimport All Maven Projects' button. It's the first button at Maven Projects tab (blue circle). Looks like this dependency wasn't downloaded from Internet yet.
I have made some test, and on my computer with fresh repositorys it is working, on the old one not.
In intellij go to settings (ctrl alt s) -> Build,execution,deployment -> Build Tools -> Maven -> Repositorys
Click on maven -> and update on the right corner.
I'm also having a lot of issues with IntelliJ and dependencies. I'm gonna share some of my trouble shooting methods for it:
- Make sure that the
pom.xmlhas the dependencies in it.
This is the very first thing to do, and I assume you've already done it.
For the next step you can either use the maven tab on the right:

which looks like this when you click it:

or right click your pom.xml and pick Maven like so:

- Reimport
It's quick and easy and sometimes that's exactly what's neccessary.

- Generate sources and Update Folders
Sometimes the sources haven't been properly generated, then this is the key.

- Download Sources
Sometimes IntelliJ doesn't do this automatically, something you can change in Settings > Build, Execution, Deployment > Build tools > Maven > Importing and enable Import Maven projects automativally.
The download Sources looks like this:

The settings button is the one furthest on the right on my example images of the Maven tab.
Last but not least:
Put your cursor on the red part of the import, (the import org.json.simple.JSONObject; part) wait for the red lamp to appear, and the choose "add to class path".
When all else is as it should, the class path needs to be updated with your import. IntelliJ doesn't always do this automatically either.
I solve this problem by adding
<scope>compile</scope>
to my missing dependency. It seems that compile is not always the default.
Strangely while IntelliJ was complaining, Eclipse was able to find the definition.
Hi all,
I am working with a JSON object and when I launch my project I get the following error:
java.lang.NoClassDefFoundError: org/json/JSONObject
viewmodels.LaunchViewModel.buildNextLaunch(LaunchViewModel.java:64)Looking at line 64...
JSONObject jsonObj = new JSONObject(getHTML("..."));Looks like I have not setup the dependencies correctly. I am working with IntelliJ with Gradle and I have imported JSON into my external libraries as seen here...
https://i.imgur.com/8VqLFf9.jpg
and here...
https://i.imgur.com/MFupkXg.jpg
My question is does it need to be added to the build.gradle file? Here are my dependencies:
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile group: 'junit', name: 'junit', version: '4.12'
}I think that may be the culprit? But I am still pretty new to this process so any pointers would be sweet.
Thanks!
Edit for mods: The two screenshots are of my external libraries, no code in those. I replaced the remaining screen shot with a code block. Thanks!
Add json jar to your classpath
or use java -classpath json.jar ClassName
Or add this to your maven pom.xml depedencies:
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
As of today (15th July 2020), you need to use latest maven repository as per below:
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20200518</version>
</dependency>
For any new version in the future, you can check it here:
- https://mvnrepository.com/artifact/org.json/json
Then simply replace 20200518 with latest new version value.
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>
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 was able to successfully download json in my gradle dependencies:
implementation 'org.json:json:20171018'
As some mentioned, mvnrepository provides snippet for different Build systems.
After you choose your desired version, in the middle of the page, select Gradle as build system, copy and paste the snippet in your build.gradle file, section dependencies in your java project.
// https://mvnrepository.com/artifact/org.json/json
compile group: 'org.json', name: 'json', version: '20180813'
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 errors