Java JSON processing - Quick Concepts and Example

[Updated: Jan 23, 2016, Created: Nov 22, 2015]

Basic Concepts

  • Java EE 7 includes support for JSR 353, which provides an API to parse, transform, and query JSON data using the object model or the streaming model
  • This API and upcoming JSON-B (Java API for JSON Binding, JEE 8, JSR 367) provides the processing/parsing and object-conversion to JSON and vice versa. JSON-P is similar to what JAXP does to XML and JSON-B is similar to JAXB in that sense.
  • Package javax.json provides API to process JSON. This package contains all interfaces except for one concrete factory class Json, so whatever you will do here, you will start with this class. JsonObject and JsonArray.
  • Package similar to the Streaming API for XML (StAX) and designed to process large amounts of JSON data efficiently instead of loading the complete JSON tree in memory.
  • javax.json.spi used by vendors to provide the implementation for above two APIs. They do that by extending JsonProvider
  • JSON Processing project is the reference implementation for JSON Processing API.
  • Don't confuse JSON-P with another acronym which stands for JSON with Padding

Quick Example

In this example we will use, Maven 3.0,4, JDK 1.8, Json API 1.0 and the reference implementation jsonp 1.0.4

  1. Create a maven project using maven-archetype-quickstart
  2. Add json-api dependecy to your pom.xml

  3. Add json-api implementation (jsonp) to our pom.xml

  4. Import the project to your IDE and do modifications as shown in the following code browser.

Example Project

Dependencies and Technologies Used:

  • JSR 353 (JSON Processing) API 1.0: API module of JSR 353:Java API for Processing JSON.
  • JSR 353 (JSON Processing) Default Provider 1.0.4: Default provider for JSR 353:Java API for Processing JSON.
  • JDK 1.8
  • Maven 3.0.4

Json Api First Example Select All Download
  • json-api-first-example
    • src
      • main
        • java
          • com
            • logicbig
              • example

See Also