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:
Answer from ivanleoncz on serverfault.comThe 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.
java - package org.json does not exist when importing org.json.JSONObject - Stack Overflow
Json library for java on netbeans - Stack Overflow
java - NetBeans error: package org does not exist - Stack Overflow
java - Importing JSON into an Netbeans project - Stack Overflow
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.
Clearing the cache fixed it. In windows 7 the cache is located in
C:\Users\username\AppData\Local\NetBeans\...
On Linux, the cache is at:
/home/username/.cache/netbeans/...
On clearing the cache, and restarting netbeans, it started to recognize org.* imports again.
I did it easily, just click the Jframe, on Navigator tab, right-click -> Set Layout -> Absolute Layout and YEP, It works for me.

As the article says you need to add the simple-json library to your project:
http://code.google.com/p/json-simple/
For this we have to add Class org.json.JSONObject which available in json-20131018.jar. We need to download this jar and add this jar to your buildpath.
for it in netbeans right click 'libraries' in the project list, then click add jar/folder.
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.
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!
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 errorsYour 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;
I have to download and add to my lib; javax.json-1.0.4.jar which gives me the Json Processing capability that I needed.
I don't believe it's true that Tomcat 8 'uses Java EE 7' in the way you think it does. Tomcat is wonderful, but it has never been a full-on Java EE. It is a servlet container, but that's not quite the same as something like JBoss. As previous poster said, download it and add it to your lib folder. I always make sure to have a local Tomcat on my dev machine, and add it's Tomcat lib as one of my global libraries. When something is not showing up, then I know I need to maven it and then add it lib in the jar/war.
FYI there is the TomEE project, http://tomee.apache.org/tomcat-java-ee.html which is a full-on Java EE version of Tomcat, but personally I like plain old Tomcat and just adding what's needed.
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>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.
Clear the cache to fix it. In Windows, cache is located at:
C:\Users\username\AppData\Local\NetBeans\...
On Linux, cache is at:
/home/username/.cache/netbeans/...
After clearing the cache restart netbeans.
If clearing the cache still doesn't work try adding the jar files themselves instead of adding the folder. Looks like a bug in Netbeans. I did it that way and worked like a charm.