JsonObject

Represents JSON object.

To parse string into JsonObject use JsonParse.

Instance attributes

Attribute values can be accessed in the same way as instance attribute (obj.key, null if the key does not exist). Assigning to an attribute (obj.key = value) works the same as set().

Instance methods

get(key) ⇒ ?

Returns attribute value by the key. Value type depends on the type used in JSON.

Table 1. Parameters

key

String

Attribute key

Return

Attribute value, or null if the key does not exist. Nested JSON objects and arrays are returned as JsonObject and JsonArray.

keys(): Array

Returns attribute array

Return

Attribute array

serialize(): String

Returns string with serialized JSON

Return

String with JSON

set(key, value): void

Sets attribute referenced by key to the given value. Accepts nested JsonArray and JsonObject values as well as other values converted to JSON. A nested JsonArray or JsonObject is stored by reference, not copied: changing it afterwards also changes this object. The same applies to attribute assignment (obj.key = value) and to nested values returned by get.

Table 2. Parameters

key

String

Attribute key

value

any

Attribute new value

setBoolean(key, value): void

Sets a boolean value at the specified key. The value is converted to boolean.

Table 3. Parameters

key

String

Attribute key

value

any

Value to convert to boolean

setNull(key): void

Sets a JSON null value at the specified key.

Table 4. Parameters

key

String

Attribute key

setString(key, value): void

Sets a string value at the specified key. The value is converted to string.

Table 5. Parameters

key

String

Attribute key

value

any

Value to convert to string

Constructors

JsonObject()

Creates new JSON object.

Return

JsonObject object

JsonObject(object)

Creates new JSON object with attributes and values from NXSL object or hashmap.

Added in version 5.3

Table 6. Parameters

object

object

NXSL object

Return

JsonObject object