O'Reilly logo

Java EE 7 with GlassFish 4 Application Server by David R. Heffelfinger

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The JSON-P Streaming API

The JSON-P Streaming API allows the sequential reading of a JSON object from a stream (a subclass of java.io.OutputStream, or a subclass of java.io.Writer). It is faster and more memory efficient than the Model API. However, the tradeoff is that it is more limited, since the JSON data needs to be read sequentially and we cannot access specific JSON properties directly, the way the Model API allows.

Generating JSON data with the Streaming API

The JSON Streaming API has a JsonGenerator class that we can use to generate JSON data and write it to a stream. This class has several overloaded write() methods which can be used to add properties and their corresponding values to the generated JSON data.

The following code sample

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required