JSONWriter

open class JSONWriter(writer: Writer = StringWriter(), prettyPrint: Boolean = false) : AutoCloseable

A stateful JSON writer that produces ASCII-only documents that adhere strictly to ECMA 404: "The JSON Data Interchange Format".

Author

Todd L Smith

Richard Arriaga

See also

Parameters

writer

The target for the raw JSON document.

prettyPrint

true indicates the JSON should be pretty-printed; false indicates the JSON should be minified.

Constructors

Link copied to clipboard
fun JSONWriter(writer: Writer = StringWriter(), prettyPrint: Boolean = false)

Construct a new JSONWriter.

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
inline fun <R> at(key: String, action: JSONWriter.() -> R): R

Write the given non-null String as the name of an entity, then evaluate the action, generally to write the associated value.

Link copied to clipboard
open override fun close()
Link copied to clipboard
fun contents(): String

Answer the accumulated String contents of the JSONWriter.

Link copied to clipboard
fun endArray()

Write an array ending to the underlying document writer.

Link copied to clipboard
fun endObject()

Write an object ending to the underlying document writer.

Link copied to clipboard
fun flush()

Flush any buffered data to the underlying document writer.

Link copied to clipboard
fun format(pattern: String?, vararg args: Any)

Write the specified String to the underlying document writer as a JSON string. All non-ASCII characters are encoded as Unicode escape sequences, so only ASCII characters will be written.

Link copied to clipboard
fun startArray()

Write an array beginning to the underlying document writer.

Link copied to clipboard
fun startObject()

Write an object beginning to the underlying document writer.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
open fun write(value: BigDecimal)

Write the specified BigDecimal to the underlying document writer as a JSON number.

fun write(value: BigInteger)

Write the specified BigInteger to the underlying document writer as a JSON number.

open fun write(value: Boolean)

Write the specified Boolean to the underlying document writer as a JSON boolean.

fun write(value: Double)

Write the specified Double to the underlying document writer as a JSON number. Use JSON 5 extensions (and an additional NaN extension).

fun write(value: Float)

Write the specified Float to the underlying document writer as a JSON number.

fun write(value: Int)

Write the specified Int to the underlying document writer as a JSON number.

fun write(value: Long)

Write the specified Long to the underlying document writer as a JSON number.

fun write(value: String?)

Write the specified String to the underlying document writer as a JSON string. All non-ASCII characters are encoded as Unicode escape sequences, so only ASCII characters will be written.

fun write(friendly: JSONFriendly)

Write the specified JSON-friendly value to the underlying document writer.

fun write(other: JSONWriter)

Write the contents of the specified JSONWriter to the underlying document as a JSON value. This is only permitted whenever an arbitrary JSON value would be permitted.

Link copied to clipboard
inline fun <R> writeArray(action: JSONWriter.() -> R): R

Write an array, using an action to supply the contents.

fun writeArray(values: Iterable<JSONFriendly>)
fun writeArray(values: Iterator<JSONFriendly>)
fun writeArray(values: Sequence<JSONFriendly>)

Write an array of JSON-friendly values.

Link copied to clipboard
fun writeBooleans(values: Iterable<Boolean>)
fun writeBooleans(values: Iterator<Boolean>)
fun writeBooleans(values: Sequence<Boolean>)

Write an array of boolean values.

Link copied to clipboard
fun writeDoubles(values: Iterable<Double>)
fun writeDoubles(values: Iterator<Double>)
fun writeDoubles(values: Sequence<Double>)

Write an array of double values.

Link copied to clipboard
fun writeFloats(values: Iterable<Float>)
fun writeFloats(values: Iterator<Float>)
fun writeFloats(values: Sequence<Float>)

Write an array of float values.

Link copied to clipboard
fun writeInts(values: Iterable<Int>)
fun writeInts(values: Iterator<Int>)
fun writeInts(values: Sequence<Int>)

Write an array of integer values.

Link copied to clipboard
fun writeLongs(values: Iterable<Long>)
fun writeLongs(values: Iterator<Long>)
fun writeLongs(values: Sequence<Long>)

Write an array of long values.

Link copied to clipboard
open fun writeNull()

Write a JSON null to the underlying document writer.

Link copied to clipboard
inline fun <R> writeObject(action: JSONWriter.() -> R): R

Write an object, using an action to supply the contents.

Link copied to clipboard
fun writeStrings(values: Iterable<String>)
fun writeStrings(values: Iterator<String>)
fun writeStrings(values: Sequence<String>)

Write an array of string values.