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
🌐
GitHub
github.com › stleary › JSON-java
GitHub - stleary/JSON-java: A reference implementation of a JSON package in Java. · GitHub
The JSON-Java package is a reference implementation that demonstrates how to parse JSON documents into Java objects and how to generate new JSON documents from the Java classes. The files in this package implement JSON encoders and decoders.
Starred by 4.7K users
Forked by 2.6K users
Languages   Java
🌐
Baeldung
baeldung.com › home › json › introduction to json-java (org.json)
Introduction to JSON-Java (org.json)
June 20, 2025 - In this tutorial, we’ll see how to create, manipulate, and parse JSON using one of the available JSON processing libraries in Java – the JSON-Java library, also known as org.json.
🌐
Maven Repository
mvnrepository.com › artifact › org.json › json
Maven Repository: org.json » json
December 24, 2025 - JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. ... JSON is a light-weight, language independent, data interchange format. See http://www.JSON.org/ The files in this package implement JSON encoders/decoders in Java.
🌐
TutorialsPoint
tutorialspoint.com › org_json › org_json_quick_guide.htm
Org.Json - Quick Guide
org.json or JSON-Java is a simple Java based toolkit for JSON. You can use org.json to encode or decode JSON data. This chapter takes you through the process of setting up Org.Json on Windows and Linux based systems.
🌐
Javadoc.io
javadoc.io › doc › org.json › json › latest › index.html
json 20251224 javadoc (org.json)
Latest version of org.json:json · https://javadoc.io/doc/org.json/json · Current version 20251224 · https://javadoc.io/doc/org.json/json/20251224 · package-list path (used for javadoc generation -link option) https://javadoc.io/doc/org.json/json/20251224/package-list ·
🌐
Stleary
stleary.github.io › JSON-java › index.html
Generated Documentation (Untitled)
JavaScript is disabled on your browser · Frame Alert · This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to Non-frame version
Find elsewhere
🌐
Maven Central
central.sonatype.com › artifact › org.json › json
Maven Central: org.json:json - Sonatype
See http://www.JSON.org/ The files in this package implement JSON encoders/decoders in Java. It also includes the capability to convert between JSON and XML, HTTP headers, Cookies, and CDL. This is a reference implementation. There are a large number of JSON packages in Java.
🌐
Stleary
stleary.github.io › JSON-java
Package org.json
JavaScript is disabled on your browser · Frame Alert · This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to Non-frame version
🌐
Javadoc.io
javadoc.io › doc › org.json › json › 20170516 › org › json › class-use › JSONObject.html
Uses of Class org.json.JSONObject
Latest version of org.json:json · https://javadoc.io/doc/org.json/json · Current version 20170516 · https://javadoc.io/doc/org.json/json/20170516 · package-list path (used for javadoc generation -link option) https://javadoc.io/doc/org.json/json/20170516/package-list ·
Top answer
1 of 4
33

Bit late, but I wanted to share my opinion on this.

I faced this problem recently when I found a Java project with both libraries and they were used at the same time.

I think that org.json is easier to read and to use, for 2 main reasons (for my needs):

  1. JsonObject is immutable. You can't add new key/value pairs to an already existing JsonObject (reference here: javax.json: Add new JsonNumber to existing JsonObject)

  2. It takes a few lines to pretty print a JsonObject or JsonArray, while it only takes 1 line to do it with JSONObject or JSONArray. Example:

    CopyStringWriter sw = new StringWriter();
    Map<String, Object> properties = new HashMap<>();
    properties.put(JsonGenerator.PRETTY_PRINTING, true);
    
    JsonWriterFactory writerFactory = Json.createWriterFactory(properties);
    JsonWriter jsonWriter = writerFactory.createWriter(sw);
    
    jsonWriter.writeObject(jsonObject); //JsonObject created before
    jsonWriter.close();
    String prettyPrintedJSON = sw.toString();
    

That is the code I use to get an indented JSON to write to a file. And with org.json I only need jsonObject.toString(4).

Another difference is the constructors. You will need a JsonObjectBuilder to create a JSON with javax.json. One step more that can be avoided.

I'm sure there are more differences (not sure if it's possible to create a JsonObject from a String) but these are my thoughts.

2 of 4
7

JSONObject, as mentioned, is provided by android's API. JsonObject is specifically used for Java EE development which is essentially for web applications and networking capabilities among other things.

The reason Android does not prepackage JsonObject from Oracle Java EE package is because alot of the things javax can do, are not allowed within android like accessing the internet without permission. This means importing the entire jars files of javax would conflict with Android.

If you plan to build your own backend with Java EE, I would highly suggest using JsonObject over JSONObject. On the other hand, if you know a prebuilt rest service or something similar that supports Android's JSON even better.

🌐
Reddit
reddit.com › r/java › the curious case of json-java (org.json) and maven's dependency "hell"
r/java on Reddit: The curious case of JSON-Java (org.json) and Maven's dependency "hell"
July 19, 2025 -

Hi. I have a recurring maven(?) issue that I hope is not unique to me and has been solved by someone somewhere.

As JSON parser, I use JSON-Java (the one with package org.json), instead of more famous ones, as the DX and API feel more fit for most/all my projects.

However, from time to time, I reach a very dreadful situation, where the "version" of the JSON-Java library that is available to my code is "not" the one that I have declared in my pom.xml file. In once case, the copyright notice in the source that I could see by clicking the class name in VSCode was from 2010, with the painful difference to the modern version that all parsing methods threw checked exceptions. In another instance, the JSONArray class did not implement Iterable/Iterator where in modern versions it does.

This is likely a maven transitive dependency issue, but the reason it is so visible for this particular library, is because either many libraries already have their own dependency on it, or that it's interface has evolved quite significantly along the way. Likely both.

The solution "in the book" for this is apparently to do "mvn dependency:tree" and exclude JSON-Java explicitly from other dependencies that depend on it. But it doesn't work for me! In my dependency three, only the recent version that is in my own pom file is shown, whereas in code/IDE (VSCode + IntelliJ), I can only use the old version. My deployment involves building a fat Jar, so it happens there too.

Am I doing something wrong? Is there a proven way to make only a certain version of a dependency available to my code, regardless of other versions that may be present deeper in the class path? Does the order of dependencies in pom file matter? and how can I strictly control the versions of dependencies that appear in my fat jar, in case it is possible at all?

Many thanks

🌐
Studytrails
studytrails.com › 2016 › 09 › 12 › java-org-json
parse Json for Java – org.json – Studytrails
September 12, 2016 - org.json has classes to parse Json for Java. It also converts between JSON and XML, HTTP header, Cookies, and CDF.
🌐
Stleary
stleary.github.io › JSON-java › org › json › JSONObject.html
JSONObject
org.json · java.lang.Object · org.json.JSONObject · public class JSONObject extends Object · A JSONObject is an unordered collection of name/value pairs. Its external form is a string wrapped in curly braces with colons between the names and values, and commas between the values and names.
🌐
Android Developers
developer.android.com › api reference › org.json
org.json | API reference | Android Developers
Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体
🌐
Javadoc.io
javadoc.io › doc › org.json › json › 20171018 › org › json › JSONObject.html
JSONObject (JSON in Java 20171018 API)
August 15, 2016 - Latest version of org.json:json · https://javadoc.io/doc/org.json/json · Current version 20171018 · https://javadoc.io/doc/org.json/json/20171018 · package-list path (used for javadoc generation -link option) https://javadoc.io/doc/org.json/json/20171018/package-list ·
🌐
SourceForge
sourceforge.net › projects › json-java.mirror › files › 20240205 › org.json-1.6-20240205.jar
Download org.json-1.6-20240205.jar (JSON-java)
This is an exact mirror of the JSON-java project, hosted at https://github.com/stleary/JSON-java. SourceForge is not affiliated with JSON-java.
🌐
GitHub
github.com › stleary › JSON-java › blob › master › src › main › java › org › json › JSONObject.java
JSON-java/src/main/java/org/json/JSONObject.java at master · stleary/JSON-java
A reference implementation of a JSON package in Java. - JSON-java/src/main/java/org/json/JSONObject.java at master · stleary/JSON-java
Author   stleary
🌐
Stleary
stleary.github.io › JSON-java › org › json › JSONArray.html
JSONArray
org.json · java.lang.Object · org.json.JSONArray · All Implemented Interfaces: Iterable<Object> public class JSONArray extends Object implements Iterable<Object> A JSONArray is an ordered sequence of values. Its external text form is a string wrapped in square brackets with commas separating ...
🌐
HCL GUVI
studytonight.com › java-examples › introduction-to-orgjson
Introduction to org.json
August 16, 2021 - Supports JavaScript, Python, Ruby, and 20+ programming languages.Explore IDE