image credit: Ismael Pérez Ortiz
Click here if you just want the latest release jar file.
JSON is a light-weight language-independent data interchange format.
The JSON-Java package is a reference implementation that demonstrates how to parse JSON documents into Java objects and how to generate new JSON documents from the Java classes.
The files in this package implement JSON encoders and decoders. The package can also convert between JSON and XML, HTTP headers, Cookies, and CDL.
Project goals include:
- Reliable and consistent results
- Adherence to the JSON specification
- Easy to build, use, and include in other projects
- No external dependencies
- Fast execution and low memory footprint
- Maintain backward compatibility
- Designed and tested to use on Java versions 1.6 - 25
This project is in the public domain. This means:
- You can use this code for any purpose, including commercial projects
- No attribution or credit is required
- You can modify, distribute, and sublicense freely
- There are no conditions or restrictions whatsoever
We recognize this can create uncertainty for some corporate legal departments accustomed to standard licenses like MIT or Apache 2.0. If your organization requires a named license for compliance purposes, public domain is functionally equivalent to the Unlicense or CC0 1.0, both of which have been reviewed and accepted by organizations including the Open Source Initiative and Creative Commons. You may reference either when explaining this project's terms to your legal team.
For more information on contributions, please see CONTRIBUTING.md
Bug fixes, code improvements, and unit test coverage changes are welcome! Because this project is currently in the maintenance phase, the kinds of changes that can be accepted are limited. For more information, please read the FAQ.
The org.json package can be built from the command line, Maven, and Gradle. The unit tests can be executed from Maven, Gradle, or individually in an IDE e.g. Eclipse.
Building from the command line
Build the class files from the package root directory src/main/java
javac org/json/*.javaCreate the jar file in the current directory
jar cf json-java.jar org/json/*.classCompile a program that uses the jar (see example code below)
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
java -cp .;json-java.jar Test (Windows)
java -cp .:json-java.jar Test (Unix Systems)Expected output
{"abc":"def"}Tools to build the package and execute the unit tests
Execute the test suite with Maven:
mvn clean testExecute the test suite with Gradlew:
gradlew clean build testOptional Execute the test suite in strict mode with Gradlew:
gradlew testWithStrictModeOptional Execute the test suite in strict mode with Maven:
mvn test -P test-strict-mode For more information, please see NOTES.md
For more information on files, please see FILES.md
For the release history, please see RELEASES.md
