Skip to content

YellowfinBI/JSON-java

 
 

Json-Java logo

image credit: Ismael Pérez Ortiz

JSON in Java [package org.json]

Maven Central

Click here if you just want the latest release jar file.

Yellowfin BI fork

This fork of JSON-java includes a couple of changes that we rely on.

Include null values when serializing objects

By default JSON-java will not serialize null properties on objects, instead omitting those properties from the resulting map.

This fork adds an includeNullValues flag to the JSONObject(Object) and JSONObject(Map) constructors. When set to true, any properties returning a null value will be included in the resulting JSONObject.

Note that this only applies at the top level object and will not affect other objects referenced in the properties or descendants.

Revert Enum handling to the original pre-2016 implementation

Enum handling in JSON-java was changed in 2016 to be more consistent and to serialize Enums to their name() value.

Originally, under some circumstances (e.g. Enum property on an Object) the Enum would have been wrapped in a JSONObject, serializing all of its fields. After the change, the default behavior is to serialize the Enum to a String containing its name() value. It is still possible to serialize an Enum to a JSONObject by explicitly wrapping it in a JSONObject.

This fork reverts the Enum handling changes to how they were handled before 2016 to ensure backwards compatability while retaining all of the other updates done to the library.

Overview

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.

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 - 1.11

The files in this package implement JSON encoders and decoders. The package can also convert between JSON and XML, HTTP headers, Cookies, and CDL.

If you would like to contribute to this project

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.

Build Instructions

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/*.java

Create the jar file in the current directory

jar cf json-java.jar org/json/*.class

Compile 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.toString());
    }
}

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 test

Execute the test suite with Gradlew:

gradlew clean build test

Notes

For more information, please see NOTES.md

Files

For more information on files, please see FILES.md

Release history:

For the release history, please see RELEASES.md

About

A reference implementation of a JSON package in Java.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%