When compiling, you must specify the absolute path to the .jar file which contains the package with its classes, like this:

javac -cp /usr/share/java/json-20160212.jar JsonParser.java

According to the official documentation from Oracle about PATH and CLASSPATH variables:

The preferred way to specify the class path is by using the -cp command line switch. This allows the CLASSPATH to be set individually for each application without affecting other applications. Setting the CLASSPATH can be tricky and should be performed with care.

The default value of the class path is ".", meaning that only the current directory is searched. Specifying either the CLASSPATH variable or the -cp command line switch overrides this value.

Answer from ivanleoncz on serverfault.com
🌐
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/
🌐
Coderanch
coderanch.com › t › 694181 › netbeans › ide › Trouble-JSON-imports
Trouble with JSON imports [Solved] (NetBeans forum at Coderanch)
May 15, 2018 - Mike Gauthier wrote:The message on the last two imports is: org.jason.simple.JSONArray does not exist. What else do I need to do? Does your import specify jason or json? ... These are the classes bundled in that jar: org.json.simple.ItemList org.json.simple.JSONArray org.json.simple.JSONAware org.json.simple.JSONObject org.json.simple.JSONStreamAware org.json.simple.JSONValue org.json.simple.parser.ContainerFactory org.json.simple.parser.ContentHandler org.json.simple.parser.JSONParser org.json.simple.parser.ParseException org.json.simple.parser.Yylex org.json.simple.parser.Yytoken
Discussions

java - package org.json does not exist when importing org.json.JSONObject - Stack Overflow
I am using: emacs 24.3.1 Fedora 20 jdk1.7.0_45 I have created a Java project using emacs and have the following project and classpath files: .project ... More on stackoverflow.com
🌐 stackoverflow.com
Json library for java on netbeans - Stack Overflow
org.json. doesn't belong to standard Java packages. You need to download it and add to project classpath. ... If you or not using maven or ant, your project still has a library/class folder. More on stackoverflow.com
🌐 stackoverflow.com
java - NetBeans error: package org does not exist - Stack Overflow
I just installed Netbeans IDE. I am now unable to import any org.* libs and it just says package org does not exist. Also, I imported jdic.jar into the project and even though the code completion More on stackoverflow.com
🌐 stackoverflow.com
java - Importing JSON into an Netbeans project - Stack Overflow
I need to import JSON library into netbeans. How can I do that? I searched on internet and I found this article. According to this article when I import import org.json.simple.JSONArray; import org... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
github.com › sendgrid › sendgrid-java › issues › 41
jar file says package does not exist · Issue #41 · sendgrid/sendgrid-java
August 11, 2014 - I imported the sendgird 1.2.0-jar.jar in a project of mine in netbeans 8.0 (java 8) when I run SendGrid.Email email = new SendGrid.Email(); I got the following exception: Exception in thread "main" java.lang.ExceptionInInitializerError at xyz.Main.main(Main.java:84) Caused by: java.lang.RuntimeException: Uncompilable source code - package org.json does not exist at com.sendgrid.SendGrid$Email.(SendGrid.java:3) If I browse the contents of the jar file, i see that the package does indeed exist.
Find elsewhere
🌐
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.
🌐
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/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.
🌐
GitHub
github.com › SpencerPark › IJava › issues › 106
package does not exist · Issue #106 · SpencerPark/IJava
May 14, 2020 - | import org.json.JSONArray; package org.json does not exist · So how to solve this · No one assigned · No labels · No labels · No projects · No milestone · None yet · No branches or pull requests ·
Author   sant527
🌐
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!
🌐
IBM
developer.ibm.com › answers › questions › 175657 › how-to-properly-make-an-import-of-jsonobject-packa
IBM Developer
February 16, 2015 - IBM Developer is the source for hands-on training and in-demand learning on relevant technologies such as generative AI, data science, Java, and more.
🌐
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>
🌐
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.