JsonArray
Represents JSON array object.
| To parse string into JsonObject use JsonParse. |
Instance attributes
- size: int
-
Number of elements in array
- values: Array
-
NXSL array with JSON array elements
Instance methods
The append, insert and set methods accept nested
JsonObject and JsonArray values as well as other
values converted to JSON. A nested JsonObject or JsonArray is stored by
reference, not copied: changing it after it was added also changes this array.
Likewise, a nested object or array returned by get is the one stored in this
array, so changing it changes this array.
inner = new JsonObject();
outer = new JsonArray();
outer.append(inner);
inner.set("name", "value");
println(outer.get(0).get("name")); // prints "value"
For the insert* and set* methods, index arguments are interpreted as signed
32-bit integers. A non-integer index causes a runtime error.
- append(value): void
-
Appends value to JSON array.
Table 1. Parameters value
?
Add value to JSON array. Value type may vary.
- get(index) ⇒ ?
-
Returns array value by the index. Value type depends on the type used in JSON.
Table 2. Parameters index
Integer
Index of element in array
ReturnElement value, or
nullif index is out of range. Nested JSON objects and arrays are returned as JsonObject andJsonArray.
- insert(index, value): bool
-
Inserts a value at the specified index, shifting subsequent elements to the right.
Table 3. Parameters index
Integer
Index of element in array
value
?
Add value to JSON array. Value type may vary.
Returntrueif the value was inserted;falseif the index is negative, greater thansize, or the insertion otherwise fails. An index equal tosizeinserts at the end of the array. Since 6.2.5
- serialize(): String
-
Returns string with serialized JSON
ReturnString with serialized JSON
- set(index, value): bool
-
Replaces the existing value at the specified index.
Table 4. Parameters index
Integer
Index of element in array
value
?
Add value to JSON array. Value type may vary.
Returntrueif the value was replaced;falseif the index is negative, greater than or equal tosize, or the replacement otherwise fails. Since 6.2.5
- appendBoolean(value): void
-
Appends a boolean value to the end of the JSON array.
Table 5. Parameters value
any
Value to convert to boolean
- appendNull(): void
-
Appends a JSON null value to the end of the JSON array.
- appendString(value): void
-
Appends a string value to the end of the JSON array.
Table 6. Parameters value
any
Value to convert to string
- insertBoolean(index, value): bool
-
Inserts a boolean value at the specified index in the JSON array.
Table 7. Parameters index
Integer
Index to insert at
value
any
Value to convert to boolean
Returntrueif the value was inserted;falseif the index is negative, greater thansize, or the insertion otherwise fails. An index equal tosizeinserts at the end of the array. Since 6.2.5
- insertNull(index): bool
-
Inserts a JSON null value at the specified index in the JSON array.
Table 8. Parameters index
Integer
Index to insert at
Returntrueif the value was inserted;falseif the index is negative, greater thansize, or the insertion otherwise fails. An index equal tosizeinserts at the end of the array. Since 6.2.5
- insertString(index, value): bool
-
Inserts a string value at the specified index in the JSON array.
Table 9. Parameters index
Integer
Index to insert at
value
any
Value to convert to string
Returntrueif the value was inserted;falseif the index is negative, greater thansize, or the insertion otherwise fails. An index equal tosizeinserts at the end of the array. Since 6.2.5
- setBoolean(index, value): bool
-
Replaces the value at the specified index with a boolean value.
Table 10. Parameters index
Integer
Index of element in array
value
any
Value to convert to boolean
Returntrueif the value was replaced;falseif the index is negative, greater than or equal tosize, or the replacement otherwise fails. Since 6.2.5
- setNull(index): bool
-
Replaces the value at the specified index with JSON null.
Table 11. Parameters index
Integer
Index of element in array
Returntrueif the value was replaced;falseif the index is negative, greater than or equal tosize, or the replacement otherwise fails. Since 6.2.5
- setString(index, value): bool
-
Replaces the value at the specified index with a string value.
Table 12. Parameters index
Integer
Index of element in array
value
any
Value to convert to string
Returntrueif the value was replaced;falseif the index is negative, greater than or equal tosize, or the replacement otherwise fails. Since 6.2.5