These JSON structures are represented as object models using the Java types JsonObject and JsonArray. It is a high-level API that provides immutable object models for JSON object and array structures. The object model API is similar to the Document Object Model (DOM) API for XML. Similarly, the streaming API provides a way to generate well-formed JSON to a stream by writing one event at a time. The streaming model is adequate for local processing where random access of other parts of the data is not required. Application code can process or discard the parser event and ask for the next event (pull the event). This gives a developer more procedural control over the JSON processing. The streaming API provides an event-based parser and allows an application developer to ask for the next event rather than handling the event in a callback. It hands over parsing and generation control to the programmer. The streaming API provides a way to parse and generate JSON in a streaming fashion. However, it is often not as efficient as the streaming model and requires more memory.
This programming model is the most flexible and enables processing that requires random access to the complete contents of the tree. The tree can then be navigated and queried. The object model API creates a random-access, tree-like structure that represents the JSON data in memory.
The Java API for JSON Processing ( JSR 353) provides portable APIs to parse, generate, transform, and query JSON using object model and streaming APIs. All popular websites offer JSON as the data exchange format with their RESTful web services. JSON is often used in Ajax applications, configurations, databases, and RESTful web services. Example of JSON representation of an object