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.

Answer from Samuel Méndez on Stack Overflow
🌐
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
throw jsonTokener.syntaxError(String.format("Strict mode error: key '%s' cannot be number", obj.toString())); ... private JSONObject(Map<?, ?> m, int recursionDepth, JSONParserConfiguration jsonParserConfiguration) {
Author   stleary
🌐
Baeldung
baeldung.com › home › json › introduction to json-java (org.json)
Introduction to JSON-Java (org.json)
June 20, 2025 - Furthermore, this library can also ... classes: JSONObject – similar to Java’s native Map-like object, which stores unordered key-value pairs...
🌐
Javadoc.io
javadoc.io › static › org.json › json › 20171018 › index.html
JSONObject (JSON in Java 20171018 API)
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
🌐
Stleary
stleary.github.io › JSON-java › org › json › JSONObject.html
JSONObject
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. The internal form is an object having get and opt methods for accessing the values by name, and ...
🌐
Android Developers
developer.android.com › api reference › jsonobject
JSONObject | 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 · 中文 – 简体
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.

🌐
TutorialsPoint
tutorialspoint.com › org_json › org_json_jsonobject.htm
Org.Json - JSONObject Class
package com.tutorialspoint; import org.json.JSONArray; import org.json.JSONObject; public class JsonDemo { public static void main(String[] args) { JSONObject jsonObject = new JSONObject(); jsonObject.put("Name", "Robert"); jsonObject.put("ID", 1); jsonObject.put("Fees", Double.valueOf(1000.21)); jsonObject.put("Active", Boolean.TRUE); jsonObject.put("Other Details", JSONObject.NULL); JSONArray list = new JSONArray(); list.put("foo"); list.put(new Integer(100)); jsonObject.put("list",list); System.out.println(jsonObject); } }
🌐
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
Find elsewhere
🌐
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.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › org.json.jsonobject
JSONObject Class (Org.Json) | Microsoft Learn
[Android.Runtime.Register("org/json/JSONObject", DoNotGenerateAcw=true)] public class JSONObject : Java.Lang.Object · [<Android.Runtime.Register("org/json/JSONObject", DoNotGenerateAcw=true)>] type JSONObject = class inherit Object · Inheritance · Object · Object JSONObject ·
🌐
Oracle
docs.oracle.com › javaee › 7 › api › javax › json › JsonObject.html
JsonObject (Java(TM) EE 7 Specification APIs)
JsonObject class represents an immutable JSON object value (an unordered collection of zero or more name/value pairs).
🌐
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 ·
🌐
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
🌐
Javadoc.io
javadoc.io › doc › org.json › json › 20171018 › org › json › JSONObject.html
JSONObject (JSON in Java 20171018 API)
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 ·
🌐
GitHub
github.com › stleary › JSON-java
GitHub - stleary/JSON-java: A reference implementation of a JSON package in Java. · GitHub
javac -cp .;json-java.jar Test.java (Windows) javac -cp .:json-java.jar Test.java (Unix Systems) Test file contents · import org.json.JSONObject; public class Test { public static void main(String args[]){ JSONObject jo = new JSONObject("{ \"abc\" : \"def\" }"); System.out.println(jo); } } Execute the Test file ·
Starred by 4.7K users
Forked by 2.6K users
Languages   Java
🌐
Couchbase
docs.couchbase.com › mobile › 3.0.0 › couchbase-lite-java › org › json › JSONObject.html
JSONObject (Couchbase, Inc. Enterprise Edition License Agreement 3.0.0-189)
If the object is an array or Collection, returns an equivalent JSONArray. If the object is a Map, returns an equivalent JSONObject. If the object is a primitive wrapper type or String, returns the object. Otherwise if the object is from a java package, returns the result of toString.
🌐
Oracle
docs.oracle.com › en › middleware › maf › 2.5.1 › reference-java-api › oracle › adfmf › json › JSONObject.html
JSONObject (Oracle Fusion Middleware Java API Reference for Oracle Mobile Application Framework)
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. The internal form is an object having get and opt methods for accessing the values by name, and ...
🌐
Javadoc.io
javadoc.io › doc › org.json › json › latest › org › json › JSONObject.html
JSONObject (JSON in Java 20251224 API)
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 ·