If you are using LibGdx, it does not come with a Gradle setup, making multi-project builds streamlined.

You need to add implementation 'org.json:json:<version>' to the dependencies block of your top-level build.gradle.

To find the latest version, see http://mvnrepository.com/artifact/org.json/json/

For example, using the latest version at the time of writing:

dependencies {
   implementation 'org.json:json:20200518'
}
Answer from Jared Burrows on Stack Overflow
🌐
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.
Discussions

java - How can I solve "org.json.simple.JSONObject cannot be resolved"? - Stack Overflow
When I try to open my jsp through Tomcat, I receive the following messages: The type org.json.simple.JSONObject cannot be resolved. It is indirectly referenced from required .class files. The method More on stackoverflow.com
🌐 stackoverflow.com
java - Importing JSON into an Eclipse project - Stack Overflow
I'm an aspiring Java programmer looking to use JSON in a project. I was following a programming tutorial (from a book) which asked me to import JSON into my project by using the following line: im... More on stackoverflow.com
🌐 stackoverflow.com
Import org.json:json as gradle dependency
Hi, I couldn’t expect this would become as difficult. I am trying to import org.json:json to be used inside my beans. Have tried many things in my build.gradle file, among others: compileClasspath( group: ‘org.json’, name: ‘json’, version: ‘20201115’ ) and implementation ... More on forum.jmix.io
🌐 forum.jmix.io
0
0
December 27, 2021
junit - Gradle dependency json-simple error - Stack Overflow
I'm fairly new to Gradle so I'm trying to build a Java project and not sure about the dependencies. I have never gotten Gradle configured to be able to do my tests or now a jar file to compile and... More on stackoverflow.com
🌐 stackoverflow.com
🌐
DigitalOcean
digitalocean.com › community › tutorials › json-simple-example
json-simple example | DigitalOcean
August 4, 2022 - For reading JSON from file, we have to use org.json.simple.parser.JSONParser class. JSONParser parse method returns JSONObject. Then we can retrieve values by passing key names. Below is json-simple example to read JSON from file. package com.journaldev.json.write; import java.io.FileNotFo...
🌐
TutorialsPoint
tutorialspoint.com › org_json › org_json_quick_guide.htm
Org.Json - Quick Guide
JSONObject class is a unordered collection of key-value pairs. It provides methods to access values by key and to put values. Following types are supported − ... package com.tutorialspoint; import org.json.JSONObject; public class JsonDemo { public static void main(String[] args) { JSONObject week = new JSONObject(); week.put("Mon", "Monday"); week.put("Tue", "Tuesday"); week.put("Wed", "Wednesday"); week.put("Thu", "Thursday"); week.put("Fri", "Friday"); System.out.println(week); } }
🌐
Jmix
forum.jmix.io › support
Import org.json:json as gradle dependency - Support - Jmix
December 27, 2021 - Hi, I couldn’t expect this would become as difficult. I am trying to import org.json:json to be used inside my beans. Have tried many things in my build.gradle file, among others: compileClasspath( group: ‘org.json’, name: ‘json’, version: ‘20201115’ ) and implementation ...
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › java › what-is-json-java-org-json
What is JSON-Java (org.json)? - GeeksforGeeks
July 17, 2022 - <dependency> <groupId>com.googlecode.json-simple</groupId> <artifactId>json-simple</artifactId> <version>1.1.1</version> </dependency> We can store the items in the form of JSONObject or JSONArray. JSONArray is nothing but the collection of multiple JSON Objects. A sample JSON object can be viewed as follows ... // Importing JSON simple library import org.json.simple.JSONObject; // Creating a public class public class JsonEncodeExample { // Calling the main method public static void main(String[] args) { // Creating an object of JSON class JSONObject geekWriterObject = new JSONObject(); // Ent
🌐
Stack Overflow
stackoverflow.com › questions › 42969716 › how-to-import-org-json-in-maven-using-dependency
java - How to import org.json in maven using dependency - Stack Overflow
I even tried using json-simple-1.1.1 dependency and json-simple-1.1 dependency and json-20140107 dependency. Error is still the same. So I don't know what is going on. So anyone help me to get the right JSON dependency in pom.xml · Finally I should import these · import org.json.JSONException; import org.json.JSONObject; java ·
🌐
Jar-Download
jar-download.com › home › org.json
Download org.json JAR files with all dependencies
July 17, 2022 - Download org.json JAR files ✓ With dependencies ✓ Documentation ✓ Source code
🌐
Maven Central
central.sonatype.com › artifact › org.json › json
org.json:json - Maven Central
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. Perhaps someday the Java community will standardize on one. Until then, choose carefully. ... <dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> <version>20251224</version> </dependency>
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.

🌐
javathinking
javathinking.com › blog › org-json-simple-cannot-be-resolved
How to Fix 'org.json.simple cannot be resolved' Error in Java: A Guide for Newbies Parsing JSON — javathinking.com
Add an import statement to your Java code to test: import org.json.simple.JSONObject; // Should now resolve! public class JsonExample { public static void main(String[] args) { JSONObject obj = new JSONObject(); // No errors!
🌐
JavaMadeSoEasy
javamadesoeasy.com › 2018 › 09 › reading-json-using-jsonsimplejsonobject.html
JavaMadeSoEasy.com (JMSE): Reading JSON using json.simple.JSONObject in java
April 14, 2022 - We can use Jackson api for for processing JSON in java. ... Solve [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Maven: Compilation failure: Compilation failure: diamond operator is not supported in -source 1.5 (use -source 7 or higher to enable diamond operator)