api / tv.twelvetone.json / Json

Json

object Json

This class serves as the entry point to the minimal-json API.

To parse a given JSON input, use the parse() methods like in this example:

To create a JSON data structure to be serialized, use the methods value(), array(), and object(). For example, the following snippet will produce the JSON string {"foo": 23, "bar": true}:

To create a JSON array from a given Java array, you can use one of the array() methods with varargs parameters:

Properties

FALSE

val FALSE: JsonValue

Represents the JSON literal false.

NULL

val NULL: JsonValue

Represents the JSON literal null.

TRUE

val TRUE: JsonValue

Represents the JSON literal true.

Functions

array

fun array(): JsonArray

Creates a new empty JsonArray. This is equivalent to creating a new JsonArray using the constructor.

fun array(vararg values: Int): JsonArray

Creates a new JsonArray that contains the JSON representations of the given int values.

fun array(vararg values: Long): JsonArray

Creates a new JsonArray that contains the JSON representations of the given long values.

fun array(vararg values: Float): JsonArray

Creates a new JsonArray that contains the JSON representations of the given float values.

fun array(vararg values: Double): JsonArray

Creates a new JsonArray that contains the JSON representations of the given double values.

fun array(vararg values: Boolean): JsonArray

Creates a new JsonArray that contains the JSON representations of the given boolean values.

fun array(vararg strings: String): JsonArray

Creates a new JsonArray that contains the JSON representations of the given strings.

object

fun object(): JsonObject

Creates a new empty JsonObject. This is equivalent to creating a new JsonObject using the constructor.

parse

fun parse(string: String): JsonValue

Parses the given input string as JSON. The input must contain a valid JSON value, optionally padded with whitespace.

fun parse(reader: Reader): JsonValue

Reads the entire input from the given reader and parses it as JSON. The input must contain a valid JSON value, optionally padded with whitespace.

value

fun value(value: Int): JsonValue

Returns a JsonValue instance that represents the given int value.

fun value(value: Long): JsonValue

Returns a JsonValue instance that represents the given long value.

fun value(value: Float): JsonValue

Returns a JsonValue instance that represents the given float value.

fun value(value: Double): JsonValue

Returns a JsonValue instance that represents the given double value.

fun value(string: String?): JsonValue

Returns a JsonValue instance that represents the given string.

fun value(value: Boolean): JsonValue

Returns a JsonValue instance that represents the given boolean value.