JSON-java icon indicating copy to clipboard operation
JSON-java copied to clipboard

Unclear relevance relative to other JSON libraries (particularly javax.json)

Open Chealer opened this issue 3 years ago • 10 comments

Our team needs to receive and send JSON and wants to use a JSON library to facilitate that. org.json provides org.json.JSONObject while javax.json-api provides javax.json.JsonObject. The purposes of both libraries are clearly similar, and while there are obvious differences like licencing (this one is public domain), it takes time for evaluators to determine how to choose between these 2 options. And there are more, including Gson and Jackson.

Please provide a comparison, either as a feature table or as free-form text to help making a choice. If a third-party offers a neutral comparison, linking to it could suffice. If not, creating a comparison which focuses on comparing to javax.json-api would already be a good start. I would prioritize listing advantages of org.json, whether in terms of performance, flexibility or simplicity, but disadvantages would also help greatly.

A few resources already help:

Chealer avatar Oct 27 '22 22:10 Chealer

The following table might help in the difference between org.json and javax.json

org.json javax.json
Package org.json javax.json
JSON Processing API Version N/A (Not a formal API) Java API for JSON Processing (Version 1.1)
Parsing Provides a simple and flexible JSON parser Provides a streaming and object model JSON parser
Writing Supports writing JSON objects and arrays Supports writing JSON objects and arrays
Size Lightweight Standard (part of Java EE and Java SE)
Dependencies Standalone library, no external dependencies Part of Java EE and Java SE, no external dependencies
Streaming Does not support streaming JSON processing Supports streaming JSON processing
Conformance May not fully conform to the JSON standard Fully conforms to the JSON standard
Performance Generally considered slower Generally considered faster
Popularity Widely used, especially in older Java projects Gaining popularity, recommended for new projects

madhavgupta2011 avatar Jul 10 '23 12:07 madhavgupta2011

@madhavgupta2011 Thank you, this is very helpful. I will look into incorporating this into the docs part of the project. Looks like streaming support and Conformance needs to be worked on. Generally considered slower? Really?

stleary avatar Jul 10 '23 15:07 stleary

The following table might help in the difference between org.json and javax.json

I'm not sure I'd agree with a lot of that comparison.

  1. The API for org.json is well defined, although not "formal". Android currently uses the same namespace and API from this project, albeit an older iteration of it.
  2. org.json fully conforms on the JSON spec for input and output. The JSON Spec specifically states that parsing of JSON may be more lax and still be conforming, while output must meet exact specifications, which org.json does.
  3. org.json support streaming by using the JSONTokener class directly, although it may not be as flexible as javax.json streaming. Unless you are implying event based streaming like an XML streaming parser may provide...
  4. I'd also like to see some comparison on performance. This project is pretty fast for many use cases and we've done performance bench-marking and improvements on it, although as far as I know, we haven't compared this library's performance to any others.

johnjaylward avatar Jul 10 '23 15:07 johnjaylward

@stleary @johnjaylward let me revise that table and send it when I get time. Thank you.

madhavgupta2011 avatar Jul 10 '23 17:07 madhavgupta2011

Please, add the license in comparision table. JSON-Java is released as public domain, Jakarta JSON Api is released with Eclipse and GPL+ GNU Classpath Exception

henryx avatar Aug 18 '23 22:08 henryx

@stleary difference between org.json and javax.json already discussed in the previous post, anything else i can do here as a beginner

@lalithabourishetty-commits Please create a file called library-comparison.md in the docs directory and populate it with the contents of the post by @madhavgupta2011 . Incorporate updates from the posts by @Chealer, @johnjaylward, and @henryx. If you want to include any other libraries in the comparison, that would be great too. You should use GitHub markdown to mark up the text.

stleary avatar Oct 04 '23 12:10 stleary

@stleary while trying to clone forked repo facing access issue, any permission do i need ?

just ignore above

@stleary :

Generally considered slower? Really?

I found this JSON library benchmark comparison project: https://github.com/fabienrenaud/java-json-benchmark

The results in the of the benchmark are displayed as graphs in the Readme. Based on this benchmark org.json is at the lower end, compared to other optimised libraries.

Simulant87 avatar Feb 22 '24 20:02 Simulant87

@stleary @johnjaylward let me revise that table and send it when I get time. Thank you.

https://olafcors7.github.io/XW2e6NOHNEu8wczhcbnrkmlZ2G9DbNZmvqpX9xjsmCtrOmUkxBwnPSnl/

Processedurinal avatar Oct 16 '25 21:10 Processedurinal