Module jakarta.json
Package jakarta.json

Interface JsonWriter

All Superinterfaces:
AutoCloseable, Closeable

public interface JsonWriter extends Closeable
Writes a JSON object or array structure to an output source.

The class Json contains methods to create writers from output sources (OutputStream and Writer).

The following example demonstrates how write an empty JSON object:

 
 JsonWriter jsonWriter = Json.createWriter(...);
 jsonWriter.writeObject(Json.createObjectBuilder().build());
 jsonWriter.close();
 
 

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

 
 JsonWriterFactory factory = Json.createWriterFactory(config);
 JsonWriter writer1 = factory.createWriter(...);
 JsonWriter writer2 = factory.createWriter(...);