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.
๐ŸŒ
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
๐ŸŒ
Jar-Download
jar-download.com โ€บ home โ€บ org.json
Download org.json JAR files with all dependencies
Download org.json JAR files โœ“ With dependencies โœ“ Documentation โœ“ Source code
๐ŸŒ
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 ยท
๐ŸŒ
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>
๐ŸŒ
JavaMadeSoEasy
javamadesoeasy.com โ€บ 2018 โ€บ 09 โ€บ reading-json-using-jsonsimplejsonobject.html
JavaMadeSoEasy.com (JMSE): Reading JSON using json.simple.JSONObject in java
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)
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.

๐ŸŒ
Cliftonlabs
cliftonlabs.github.io โ€บ json-simple
json-simple
September 3, 2022 - Minting keys directly should be used with discretion, like when another default value other than the one defined in the enum should be used in a specific case, while the enum is used in general cases. import java.io.IOException; import java.io.StringWriter; import java.io.Writer; import java.util.NoSuchElementException; import com.github.cliftonlabs.json_simple.JsonArray; import com.github.cliftonlabs.json_simple.JsonException; import com.github.cliftonlabs.json_simple.JsonKey; import com.github.cliftonlabs.json_simple.JsonObject; import com.github.cliftonlabs.json_simple.Jsonable; import com.github.cliftonlabs.json_simple.Jsoner; /** Jsonable practical example implementation with notes on alternative implementations when more flexibility may be * needed for your project.