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 Overflow
🌐
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.
🌐
Stack Overflow
stackoverflow.com › questions › 74081905 › error-package-org-json-simple-does-not-exist-vs-code
java - error: package org.json.simple does not exist VS Code - Stack Overflow
I am trying to use json.simple package for a school project and it is repeatedly giving me the same error "error: package org.json.simple does not exist". At first VS Code gave me the error while importing so I have added the json-simple-1.1.1.jar file to the reference library.
Discussions

package does not exist
[provide a description of the issue] Environment Operating System: macos sierra JDK version: 1.8 Visual Studio Code version: 1.23.1 Java extension version: 0.25.0 Steps To Reproduce download https:... More on github.com
🌐 github.com
9
May 31, 2018
java - org.json cannot be resolved to a module? - Stack Overflow
I'm learning Java. To read JSON in my application, I downloaded this JSON library; which is an automatic module. I included that library in my module descriptor like: module art { exports art.... More on stackoverflow.com
🌐 stackoverflow.com
October 11, 2020
Can't import "json-20240303" library into my project.
Show your pom.xml More on reddit.com
🌐 r/javahelp
7
2
June 17, 2024
error: package org.json does not exist
Has maven downloaded the dependencies? More on reddit.com
🌐 r/CodingHelp
2
1
April 28, 2022
🌐
GitHub
github.com › redhat-developer › vscode-java › issues › 546
package does not exist · Issue #546 · redhat-developer/vscode-java
May 31, 2018 - Got some warnings. import says "package org.json does not exist", JSONObject says "cannot find symbol",
Published   May 31, 2018
Author   tsonglew
🌐
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/
Top answer
1 of 1
1

TL;DR — As this unresolved 'Cannot be resolved' errors in projects with module-info.java issue reports, vscode is brain dead when it comes to JPMS and module-info.java.


The long-winded version

From my own experience, I can personally vouch for what the reporter of the above-linked vscode issue reports…

…I've tried both Gradle and Maven…

…I find that Gradle and Maven will automatically refresh the classpath file and remove my modifications to it, which will bring back the errors…

…there needs to be module path information set in the classpath file in order for Eclipse to be happy, but there is no good way to do with that from Gradle or Maven…

Proof that it's a vscode issue is that the exact same project — unchanged except for the removal of your comment — compiles perfectly fine in IntelliJ…

Since your project uses neither Maven nor Gradle — opting instead to use file-based dependency mgt with the jar in the lib folder — you're in even worse shape because you've eliminated the option of applying any JPMS-enabling plugins that could resolve the issue.

For example, by adding the following pom.xml with the appropriate configuration for the maven-compiler-plugin to my experimental version of your project…

…
<dependencies>
    <dependency>
       <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20200518</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>11</source>
                <target>11</target>
                <compilerArgs>
                    <arg>-Xlint:unchecked</arg>
                    <arg>--add-modules</arg>
                    <arg>org.json</arg>
                </compilerArgs>
            </configuration>
        </plugin>
    </plugins>
</build>
…

…Maven does its magic and processes the module-info.java successfully…

I've successfully resolved other Stackers' JPMS woes by helping them apply that mrJar plugin mentioned in that vscode bug report. So if you're open to using Gradle instead of Maven, I could likewise advise you on how to configure that plugin too.

🌐
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.
Find elsewhere
🌐
YouTube
youtube.com › watch
Importing json in java visual studio code | the import org.json cannot be resolved, Solved! - YouTube
In this video, we will learn how to import jsonsimple in java visual studio code project or we will learn to solve following error in visual studio codethe i...
Published   October 11, 2020
🌐
Reddit
reddit.com › r/codinghelp › error: package org.json does not exist
r/CodingHelp on Reddit: error: package org.json does not exist
April 28, 2022 -

Hi,

I am using java to create a custom nifi processor and i am trying to use the org.json.simple package to access some information from a json. When i try to compile my code i keep getting the error in the title. below is a my pom.xml:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>

 <parent>
     <groupId>1</groupId>
     <artifactId>1</artifactId>
     <version>1</version>
 </parent>

 <artifactId>nifi-processor_stuff-nar</artifactId>
 <version>1</version>
 <packaging>nar</packaging>
 <properties>
     <maven.javadoc.skip>true</maven.javadoc.skip>
     <source.skip>true</source.skip>
 </properties>

 <dependencies>
     <dependency>
         <groupId>1</groupId>
         <artifactId>nifi-processor_stuff-processors</artifactId>
         <version>1</version>
         </dependency>
     <dependency>
         <groupId>com.googlecode.json-simple</groupId>
         <artifactId>json-simple</artifactId>
         <version>1.1.1</version>
     </dependency>
 </dependencies>

</project>
🌐
GitHub
github.com › stleary › JSON-java › issues › 514
Visual Studio Code not recognizing json.org.simple as a dependency · Issue #514 · stleary/JSON-java
April 28, 2020 - Hi, I'm working on a project with 3 other people and they have downloaded and successfully used this package. I am using Visual Studio Code and they are using Eclipse and jGrasp. However, I keep getting compilation errors for this packag...
Author   Snehby
🌐
Reddit
reddit.com › r/learnjava › error: package org.json does not exist
r/learnjava on Reddit: error: package org.json does not exist
May 4, 2019 -

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!

🌐
Reddit
reddit.com › r/learnprogramming › "error: package org.json.simple does not exist" why?
r/learnprogramming on Reddit: "error: package org.json.simple does not exist" Why?
November 1, 2022 -

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.

Top answer
1 of 5
43

Try this VS Code command...

View -> Command Palette -> Java: Clean Java Language Server Workspace

This command resolved my similar issue with VS Code not recognizing import org.json.* inside the .java files of a Gradle project even though Gradle would build and run successfully. This VS Code command is similar to IntelliJ's File -> Invalidate Caches and Restart in that it forces a refresh of the IDE's cache of available tokens and identifiers.

Side Notes:

  • Make sure to have run your build tool (e.g. gradle build or mvn install) at least once so that the required packages are downloaded to your local computer so VS Code can find them.
  • This command comes with the VS Code extension "Language Support for Java" from Red Hat (redhat.java) which comes bundled in the "Java Extension Pack" from Microsoft (vscjava.vscode-java-pack). You'll have to have one of these extensions installed to use it.
2 of 5
1

I've done all the Java server cleaning and still getting '''package org.apache.lucene.analysis.tokenattributes does not exist(compiler.err.doesnt.exist)'''

build.gradle: 
    ext.pluginApiVersion = '8.12.2'
    ext.luceneVersion = '8.11.3'

    dependencies {
      implementation "org.apache.lucene:lucene- 
   core:${luceneVersion}"
      implementation "org.apache.lucene:lucene-analyzers- 
   common:${luceneVersion}"
      implementation 
    "org.elasticsearch:elasticsearch:${pluginApiVersion}"
      implementation 
    "org.elasticsearch.plugin:elasticsearch-plugin- 
   api:${pluginApiVersion}"
      implementation 
    "org.elasticsearch.plugin:elasticsearch-plugin-analysis- 
   api:${pluginApiVersion}"
    }
🌐
Google Groups
groups.google.com › g › j2objc-discuss › c › O-t4wGix9J8
Parser.java:3: package org.json does not exist
December 10, 2020 - That's correct. The org.json API is not part of the Java Runtime, and so developers shouldn't expect it to be on the bootclasspath.
🌐
Stack Overflow
stackoverflow.com › questions › 75187461 › java-vscode-error-package-does-not-exist
visual studio code - Java/VSCode. Error Package Does Not Exist - Stack Overflow
I have the following directory structure. I'm trying to import .jar files downloaded from the Maven repository. Unfortunately, I'm getting a "Package Does Not Exist Error" for databind and
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 6135911711634-Package-org-json-simple-x-Does-not-Exist
Package org.json.simple.x Does not Exist – IDEs Support (IntelliJ Platform) | JetBrains
When i Attempt to Build My Project i get 'package org.json.simple does not exist' as an Error, In the Normal View it does not mark any errors, only When Building, Help would be appreciated!
🌐
Reddit
reddit.com › r/vscode › java "package does not exist" unable to compile
r/vscode on Reddit: Java "Package does not exist" Unable to compile
April 19, 2023 -

Hello I am having trouble with Java recognizing the existence of a package that comes included in a library that I have downloaded. Before it avoided its existence, vscode was telling me that the "package could not be resolved". I have tried to "clean the workspace", but it does not work. Here is what the terminal shows

Tweets.java:1: error: package tester does not exist

import tester.Tester;

Tweets.java:70: error: cannot find symbol

boolean testIsStartOfThreadByTextTweetValid(Tester t) {

symbol: class Tester

UPDATE* Here is the code I have written

import tester.Tester;
interface Tweet {
public boolean isStartOfThreadBy(String author);
public int totalLikes();
public String unrollThread();
}
class TextTweet implements Tweet{
String author;
String contents;
int likes;
TextTweet(String author, String contents, int likes) {
this.author = author;
this.contents = contents;
this.likes = likes;
}

public boolean isStartOfThreadBy(String author) {
if (this.author.equals(author))
return true;

return false;
}
public int totalLikes(){
return likes;
}
public String unrollThread(){
String s = author + "\n" + likes +"\n" + contents + "\n";
return s;
}
class ReplyTweet implements Tweet{
String contents;
int likes;
String author;

Tweet replyTo;

public ReplyTweet(String contents, int likes, String author, Tweet replyTo){
this.contents = contents;
this.likes = likes;
this.author = author;
this.replyTo = replyTo;
}

public boolean isStartOfThreadBy(String author) {
if (this.author.equals(author) && this.replyTo.isStartOfThreadBy(author)){
return true;
}
return false;
}

public int totalLikes() {
return likes + replyTo.totalLikes();
}
public String unrollThread(){
String s = replyTo.unrollThread() + author + "\n" + likes +"\n" + contents + "\n";
return s;
}

}
public class Tweets {
boolean testIsStartOfThreadByTextTweetValid(Tester t) {
TextTweet f1= new TextTweet("John", "Hello", 5);
return t.checkExpect(f1.isStartOfThreadBy("John"), true);

The jar file that I am trying to get to work is called "tester.jar" and it is within the folder/library I am working with right now for this project.

🌐
GitHub
github.com › redhat-developer › vscode-java › issues › 161
pckage * does not exist, even though I can click through the class and get it to open in the editor · Issue #161 · redhat-developer/vscode-java
March 7, 2017 - file: 'file:///Users/tor/java/src/karriere/frontend/src/main/java/no/karriere/admin/controller/AdminController.java' severity: 'Error' message: 'package javax.servlet does not exist' at: '20,21' source: 'javac'
Author   tveimo