🌐
Javadoc.io
javadoc.io › doc › org.json › json › 20170516 › org › json › class-use › JSONObject.html
JSONObject - json 20170516 javadoc
Bookmarks · 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 · Close
🌐
Oracle
docs.oracle.com › javaee › 7 › api › javax › json › JsonObject.html
JsonObject (Java(TM) EE 7 Specification APIs)
A JsonObject instance can be created from an input source using JsonReader.readObject().
🌐
Javadoc.io
javadoc.io › doc › org.json › json › 20171018 › org › json › JSONObject.html
JSONObject - json 20171018 javadoc
Bookmarks · 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 · Close
🌐
Miamarti
miamarti.github.io › HorusFramework › javadoc › org › json › simple › JSONObject.html
JSONObject
A JSON object. Key value pairs are unordered. JSONObject supports java.util.Map interface.
🌐
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
🌐
Javadoc.io
javadoc.io › doc › com.google.code.gson › gson › latest › com.google.gson › com › google › gson › JsonObject.html
JsonObject - gson 2.13.2 javadoc
Bookmarks · Latest version of com.google.code.gson:gson · https://javadoc.io/doc/com.google.code.gson/gson · Current version 2.13.2 · https://javadoc.io/doc/com.google.code.gson/gson/2.13.2 · package-list path (used for javadoc generation -link option) · https://javadoc.io/doc/com.go...
🌐
Processing
processing.github.io › processing-javadocs › core › processing › data › JSONObject.html
JSONObject
A JSONObject constructor can be used to convert an external form JSON text into an internal form whose values can be retrieved with the get and opt methods, or to convert values into a JSON text using the put and toString methods. A get method returns a value if one can be found, and throws ...
🌐
Javadoc.io
javadoc.io › static › org.json › json › 20171018 › index.html
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
🌐
Javadoc.io
javadoc.io › doc › com.google.code.gson › gson › 2.8.5 › com › google › gson › JsonObject.html
JsonObject - gson 2.8.5 javadoc
Bookmarks · Latest version of com.google.code.gson:gson · https://javadoc.io/doc/com.google.code.gson/gson · Current version 2.8.5 · https://javadoc.io/doc/com.google.code.gson/gson/2.8.5 · package-list path (used for javadoc generation -link option) · https://javadoc.io/doc/com.goog...
Find elsewhere
🌐
Javadoc.io
javadoc.io › doc › org.json › json › latest › org › json › JSONObject.html
JSONObject - json 20251224 javadoc
Bookmarks · 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 · Close
🌐
Google
developers.google.com › j2objc › jsonobject
JSONObject | J2ObjC | Google for Developers
If the object is null or , returns NULL. If the object is a JSONArray or JSONObject, no wrapping is necessary. If the object is NULL, no wrapping is necessary. If the object is an array or Collection, returns an equivalent JSONArray. If the object is a Map, returns an equivalent JSONObject.
🌐
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 › static › org.json › json › 20210307 › org › json › JSONObject.html
JSONObject (JSON in Java 20210307 API) - javadoc.io
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 › index.html
json 20251224 javadoc (org.json)
Bookmarks · 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 · Close
🌐
SourceForge
json-lib.sourceforge.net › apidocs › net › sf › json › JSONObject.html
JSONObject (Overview (json-lib jdk 1.3 API))
A JSONObject constructor can be used to convert an external form JSON text into an internal form whose values can be retrieved with the get and opt methods, or to convert values into a JSON text using the element and toString methods. A get method returns a value if one can be found, and throws ...
🌐
SourceForge
json-lib.sourceforge.net › apidocs › jdk15 › net › sf › json › JSONObject.html
JSONObject (Overview (json-lib jdk 5 API))
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 ...
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.