Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Jakarta JSON Processing (JSON-P) is a Java API for parsing, generating, transforming, and querying JSON. It offers two main approaches: a sequential streaming API for processing events as they arrive, and an object model that loads JSON into navigable structures. Choose streaming when you can handle data in sequence; choose the object model when you need convenient access to the complete document.

What JSON-P does

JSON-P is an API for working with JSON in Java. It is not a JSON data format or a schema language. The Jakarta documentation describes it as providing portable APIs to parse, generate, transform, and query JSON through either streaming or an object model. See the Jakarta JSON Processing 2.1 API documentation.

The two approaches address different processing needs. Streaming exposes a document as a sequence of events that your code advances through. The object model represents JSON as a tree that your code can navigate. Both can read and produce JSON, but they differ in how much of the document your application works with at once.

Streaming or object model: which should you choose?

Approach How it works Best fit Trade-off
Streaming JsonParser provides forward, read-only access to JSON events; JsonGenerator writes JSON incrementally. Sequential processing that can handle or discard data as it arrives, without needing random access to the rest of the document. Gives control over event-by-event processing and avoids requiring a complete in-memory tree for local processing. Your code must work with the sequence of events.
Object model JsonReader reads a JSON value into a model; JsonObject and JsonArray represent structures that can be navigated. Code that needs convenient navigation or random access to the complete JSON structure. More flexible for navigating the whole document, but retains the structure in memory and can be less efficient.

This is qualitative guidance in the official documentation, not a measured performance comparison. Document size alone does not determine the right choice: consider whether your task needs the whole structure available at once or can process it sequentially.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How the object-model workflow fits together

The object model is useful when an application needs to inspect or construct structured JSON. A reader produces a value such as a JsonObject or JsonArray; builders assemble structures; and a writer sends a model to a destination. An object view behaves like a map of name/value pairs, while an array view behaves like an ordered list.

  1. Create a reader with Json.createReader(...) and read the JSON value.
  2. Inspect the returned JsonObject or JsonArray using the model’s navigation methods.
  3. When creating JSON in code, use Json.createObjectBuilder() or an array builder to assemble a structure.
  4. Write a model to a destination with a JsonWriter.

The Jakarta EE Tutorial’s JSON Processing chapter demonstrates readers, builders, writers, and generators. The chapter was last updated for Jakarta EE 9.1, so check the API documentation for the version and namespace used by your project before adopting an example.

Core JSON-P interfaces and types

  • Json supplies factory methods for creating parsers, builders, generators, and their factories.
  • JsonReader and JsonWriter read an object model from and write it to a source or destination.
  • JsonObjectBuilder and JsonArrayBuilder assemble object and array structures.
  • JsonValue and JsonStructure are common model types; JsonObject and JsonArray represent JSON structures.
  • JsonParser and JsonGenerator are the streaming interfaces for reading events and writing JSON incrementally.
  • JsonPointer, JsonPatch, and JsonMergePatch support locating JSON values and applying changes to JSON values or resources.
  • jakarta.json.spi defines the service-provider interface used to plug in JSON processing implementations.

Which package namespace and version should Java developers use?

For current Jakarta JSON Processing examples, look for the jakarta.json.* namespace. Older Java EE-era examples may use javax.json.*; those imports identify a different API generation and should not be copied into a Jakarta-based project without checking compatibility.

The Eclipse Jakarta JSON Processing project identifies JSON-P 2.0 as the first Eclipse project release under jakarta.json.*. The Jakarta JSON Processing specification index lists version 2.1 for Jakarta EE 10 and version 2.2 as under development for Jakarta EE 12. The index does not establish 2.2 as a released final version, so do not treat it as one.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When using code from an older tutorial or Java EE project page, check its imports, API signatures, and target version against the documentation for the API version you are using. The legacy Java EE JSON-P project page is useful for historical context, not as a substitute for checking Jakarta-era package names.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

JSON-P in a Java application

JSON-P provides lower-level processing tools: you choose whether to handle events or navigate a JSON tree, and you work with JSON values and structures through its API. That makes it a fit when the application needs explicit control over parsing, generation, or changes to JSON. If the central requirement is mapping JSON directly to Java objects, JSON-P’s streaming and object-model distinction is not itself an object-to-object binding workflow; evaluate an API intended for that binding need separately.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.