oracle.dbtools.plugin.api.json

## 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

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `JSONWriter` | `append(JSONToken token)` Write a `JSONToken` instance to the stream.
    `JSONWriter` | `endArray()` End an array, emit the closing square bracket (`]`).
    `JSONWriter` | `endObject()` End an object, emit the closing brace (`}`).
    `JSONWriter` | `nullValue()` Emit a null property value.
    `JSONWriter` | `property(String name, CharSequence value)` Emit a property with a textual value.
    `JSONWriter` | `propertyName(String name)` Emit the name of a property
    `JSONWriter` | `startArray()` Start an array, emit the opening square bracket(`[`)
    `JSONWriter` | `startObject()` Start an object, emit the opening brace (`{`).
    `JSONWriter` | `value(Boolean value)` Emit a boolean value, mapping it to the unquoted values: `true` or `false`
    `JSONWriter` | `value(CharSequence value)` Emit a textual value, quoting and escaping the string
    `JSONWriter` | `value(Number value)` Emit a numeric value.
    `JSONWriter` | `value(Readable value)` Emit a textual value, quoting and escaping the string.

    - ### Methods inherited from interface java.io.Flushable

      `flush`

    - ### Methods inherited from interface java.io.Closeable

      `close`

- - ### Method Detail

    - #### append

          JSONWriter append(JSONToken token)
                     throws JSONIOException

      Write a `JSONToken` instance to the stream.
      Parameters:
        `token` - The token to write
      Returns:
        self
      Throws:
        `JSONIOException` - if an IO error occurs

    - #### endObject

          JSONWriter endObject()
                        throws JSONIOException

      End an object, emit the closing brace (`}`).
      Returns:
        self
      Throws:
        `JSONIOException` - if an IO error occurs

    - #### endArray

          JSONWriter endArray()
                       throws JSONIOException

      End an array, emit the closing square bracket (`]`).
      Returns:
        self
      Throws:
        `JSONIOException` - if an IO error occurs

    - #### propertyName

          JSONWriter propertyName(String name)
                           throws JSONIOException

      Emit the name of a property
      Parameters:
        `name` - The name of the property
      Returns:
        self
      Throws:
        `JSONIOException` - if an IO error occurs

    - #### property

          JSONWriter property(String name,
                              CharSequence value)
                       throws JSONIOException

      Emit a property with a textual value.
      Parameters:
        `name` - Name of the property
        `value` - The value of the property
      Returns:
        self
      Throws:
        `JSONIOException` - if an IO error occurs

    - #### startObject

          JSONWriter startObject()
                          throws JSONIOException

      Start an object, emit the opening brace (`{`).
      Returns:
        self
      Throws:
        `JSONIOException` - if an IO error occurs

    - #### startArray

          JSONWriter startArray()
                         throws JSONIOException

      Start an array, emit the opening square bracket(`[`)
      Returns:
        self
      Throws:
        `JSONIOException` - if an IO error occurs

    - #### value

          JSONWriter value(Boolean value)
                    throws JSONIOException

      Emit a boolean value, mapping it to the unquoted values: `true` or `false`
      Parameters:
        `value` - boolean value
      Returns:
        self
      Throws:
        `JSONIOException` - if an IO error occurs

    - #### value

          JSONWriter value(CharSequence value)
                    throws JSONIOException

      Emit a textual value, quoting and escaping the string
      Parameters:
        `value` - textual value
      Returns:
        self
      Throws:
        `JSONIOException` - if an IO error occurs

    - #### value

          JSONWriter value(Number value)
                    throws JSONIOException

      Emit a numeric value. Note that the special Double values:
      - `Double.NaN`
      - `Double.POSITIVE_INFINITY`
      - `Double.NEGATIVE_INFINITY`
      are quoted, because the JSON syntax does not define any equivalent values.
      Parameters:
        `value` - Numeric value
      Returns:
        self
      Throws:
        `JSONIOException` - if an IO error occurs

    - #### value

          JSONWriter value(Readable value)
                    throws JSONIOException

      Emit a textual value, quoting and escaping the string.
      Parameters:
        `value` - textual value
      Returns:
        self
      Throws:
        `JSONIOException` - if an IO error occurs

    - #### nullValue

          JSONWriter nullValue()
                        throws JSONIOException

      Emit a null property value.
      Returns:
        self
      Throws:
        `JSONIOException` - if an IO error occurs

Copyright © 2010, 2022, Oracle and/or its affiliates.