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.

Answer from Bao Pham on Stack Overflow
Discussions

java - Getting - package org.json does not exist - unable to use JSONArray / JSONObject - Stack Overflow
I am trying to write a program in Java using Maven in IntelliJ which calls an API using HttpURLConnection and parses the response using JSONArray and JSONObject. I have attempted to import the org.json JAR file, and I've updated my pom.xml to include it as a dependency, but I'm still getting ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
java - Idea Intellij: Dependency org.json:json:20180813 not found, can't import org.json library in maven - Stack Overflow
I try to add the following dependency in my pom.xml file: org.json json 20180813 More on stackoverflow.com
๐ŸŒ stackoverflow.com
Intellij IDEA can't find a class in successfully imported Maven dependency - Stack Overflow
Intellij IDEA says that everything is fine, dependency is successfully imported. However, it cannot find any json-simple classes in the editor, saying "Cannot resolve symbol 'JSONObject'. More on stackoverflow.com
๐ŸŒ stackoverflow.com
I have a little problem
Couldn't load subscription status. Retry ยท There was an error while loading. Please reload this page More on github.com
๐ŸŒ github.com
9
October 5, 2021
๐ŸŒ
Reddit
reddit.com โ€บ r/javahelp โ€บ can't import "json-20240303" library into my project.
r/javahelp on Reddit: Can't import "json-20240303" library into my project.
June 17, 2024 -

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.

Top answer
1 of 3
2
Show your pom.xml
2 of 3
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
Top answer
1 of 3
23

I'm also having a lot of issues with IntelliJ and dependencies. I'm gonna share some of my trouble shooting methods for it:

  1. Make sure that the pom.xml has 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:

  1. Reimport

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

  1. Generate sources and Update Folders

Sometimes the sources haven't been properly generated, then this is the key.

  1. 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.

2 of 3
3

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.

๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 666886 โ€บ java โ€บ package-org-json-exist
package org.json does not exist [Solved] (Beginning Java forum at Coderanch)
Here are some details: $ echo $CLASSPATH /usr/share/java $ ll /usr/share/java/json* -rw-r--r-- 1 root root 49176 Jun 12 22:31 /usr/share/java/json-20160212.jar $ jar tf /usr/share/java/json-20160212.jar META-INF/MANIFEST.MF META-INF/ META-INF/maven/ META-INF/maven/org.json/ META-INF/maven/org.json/json/ META-INF/maven/org.json/json/pom.properties META-INF/maven/org.json/json/pom.xml org/ org/json/ org/json/CDL.class org/json/Cookie.class org/json/CookieList.class org/json/HTTP.class org/json/HTTPTokener.class org/json/JSONArray.class org/json/JSONException.class org/json/JSONML.class org/json/
Find elsewhere
๐ŸŒ
GitHub
github.com โ€บ stleary โ€บ JSON-java โ€บ issues โ€บ 624
I have a little problem ยท Issue #624 ยท stleary/JSON-java
October 5, 2021 - Can you please help me sort this out? I keep getting a error massage. import org.json.JSONArray; import org.json.JSONObject; public class Main { public static void main(String[] args) { String jsonStr = "{ \"Number1\" : 123.456 , \"Numbe...
Author ย  MagFra
๐ŸŒ
Reddit
reddit.com โ€บ r/javahelp โ€บ noclassdeffounderror: org/json/jsonobject
r/javahelp on Reddit: NoClassDefFoundError: org/json/JSONObject
September 27, 2017 -

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!

Top answer
1 of 2
2
Intellij has its own build system, it can auto sync with gradle but not the other way around, you can't use the library imported from Intellij if you want to use gradle. If you want to use Gradle build, add the dependency into build.gradle: compile group: 'org.json', name: 'json', version: '20180130' But if you want to run it from Intellij, make sure the classpath is configured correctly
2 of 2
1
It seems that you possibly have a screenshot of code in your post NoClassDefFoundError: org/json/JSONObject in r/javahelp . Screenshots of code instead of actual code text is against the Code posting rules of /r/javahelp as is also outlined in the sidebar - Code posting. Never submit screenshots of code instead of code text! If you posted an image merely to illustrate something, kindly ignore this message and do not repost. Your post is still visible to others. I am a bot and cannot distinguish between code screenshots and other images. If you indeed did this wrong, please edit the post so that it uses one of the approved means of posting code. For small bits of code (less than 50 lines in total, single classes only), the default code formatter is fine (one blank line before the code, then 4 spaces before each line of code). Pastebin for programs that consist of a single class only Gist for multi-class programs, or programs that require additional files Github or Bitbucket repositories are also perfectly fine as are other dedicated source code hosting sites. Ideone for executable code snippets that use only the console Please do not reply to this message, because I am a bot. Talk-to-the-bot is the new talk-to-the-hand. If you instead want the classic talk-to-the-hand, just message the moderators. ;) I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
๐ŸŒ
JetBrains
intellij-support.jetbrains.com โ€บ hc โ€บ en-us โ€บ community โ€บ posts โ€บ 4839591868690-JSONObject-and-JSONParser
JSONObject and JSONParser โ€“ IDEs Support (IntelliJ Platform) | JetBrains
Hi there, I am trying to implement a JSONObject and a JSONParser but I receive an error message stating that the library cannot be found. Here is what I am typing. import org.json.simple.JSONObject...
๐ŸŒ
CodingTechRoom
codingtechroom.com โ€บ question โ€บ -import-json-library-intellij-idea
How to Import the JSON Library into IntelliJ IDEA? - CodingTechRoom
Open your IntelliJ IDEA and load your project. Navigate to `File` > `Project Structure` > `Modules`. Select your module and click on `Dependencies`. Here, you can add the library directly. Alternatively, use Maven or Gradle to add the JSON library as a dependency.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ org_json โ€บ org_json_quick_guide.htm
Org.Json - Quick Guide
package com.tutorialspoint; import org.json.Cookie; import org.json.JSONObject; public class JsonDemo { public static void main(String[] args) { String cookie = "username = Mark Den; expires = Thu, 15 Jun 2026 12:00:00 UTC; path = /"; JSONObject jsonObject = Cookie.toJSONObject(cookie); //Case 2: Converts JSONObject to Cookie String System.out.println(Cookie.toString(jsonObject)); } }
๐ŸŒ
Reddit
reddit.com โ€บ r/javahelp โ€บ error: org.json does not exist
r/javahelp on Reddit: Error: org.json does not exist
April 18, 2022 -

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
Top answer
1 of 2
4
I'm not used to VSCode but evidently the library is used to compile but not at runtime. Perhaps you have to add it somewhere else, maybe in the run configuration? PS if you want to keep your sanity while developing in java, i strongly suggest to use maven to automate dependencies (unless this is homework then maybe not).
2 of 2
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
๐ŸŒ
Jar-Download
jar-download.com โ€บ home โ€บ org.json
Download org.json JAR files with all dependencies
Download org.json JAR files โœ“ With dependencies โœ“ Documentation โœ“ Source code
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 40517564 โ€บ maven-jersey-org-json-classnotfoundexception-despite-import-dependency-and
java - Maven, jersey, org.json - ClassNotFoundException despite import, dependency and classpath being correct - Stack Overflow
November 9, 2016 - I'm using intellij idea and Maven for this project - a glassfish-based REST webservice. I'm trying to execute the following method: import org.json.*; public void loadDestinations() throws Exception{ InputStream is = InfoLoader.class.getResourceAsStream("/destinations.json"); String jsonTxt = is.toString(); JSONObject obj = new JSONObject(jsonTxt); JSONArray arr = obj.getJSONArray("destinations"); //etc...