Interface JSONWriter

All Superinterfaces:
AutoCloseable, Closeable, Flushable

public interface JSONWriter extends Flushable, Closeable
Writes JSON content to a character stream.

Examples

Writing a basic object

 final JSONStreams json = ...; // acquire the JSONStreams service
 final Appendable output = ...; // create a stream to write to
 ...
 final JSONWriter writer = json.jsonWriter(output);
 
 writer.startObject().property("foo","bar").endObject(); //writes: {"foo":"bar"}
 

Writing a nested object

 final JSONStreams json = ...; // acquire the JSONStreams service
 final Appendable output = ...; // create a stream to write to
 ...
 final JSONWriter writer = json.jsonWriter(output);
 
 writer.startObject()
       .propertyName("nested")
        .startObject()
         .property("foo","bar")
        .endObject()
       .endObject(); //writes: {"nested":{"foo":"bar"}}
 

Writing an array value

 final JSONStreams json = ...; // acquire the JSONStreams service
 final Appendable output = ...; // create a stream to write to
 ...
 final JSONWriter writer = json.jsonWriter(output);
 
 writer.startObject()
       .propertyName("items")
        .startArray()
         .value("first")
         .value("second")
         .nullValue()
        .endObject()
       .endObject(); //writes: {"items":["first","second",null]}
 
Author:
cdivilly