Module jakarta.json
Package jakarta.json

Interface JsonReader

All Superinterfaces:
AutoCloseable, Closeable

public interface JsonReader extends Closeable
Reads a JSON object or an array structure from an input source.

The class Json contains methods to create readers from input sources (InputStream and Reader).

The following example demonstrates how to read an empty JSON array from a string:

 
 JsonReader jsonReader = Json.createReader(new StringReader("[]"));
 JsonArray array = jsonReader.readArray();
 jsonReader.close();
 
 

The class JsonReaderFactory also contains methods to create JsonReader instances. A factory instance can be used to create multiple reader instances with the same configuration. This the preferred way to create multiple instances. A sample usage is shown in the following example:

 
 JsonReaderFactory factory = Json.createReaderFactory(config);
 JsonReader reader1 = factory.createReader(...);
 JsonReader reader2 = factory.createReader(...);