JSON::array

Description

This command is a group of subcommands that operate on a JSON array (first parameter of each subcommand).

Syntax

JSON::array size <array>
JSON::array type <array> <index>
JSON::array get <array> <index> [<type>]
JSON::array set <array> <index> <type> [<value>]
JSON::array insert <array> <index> <type> [<value>]
JSON::array append <array> <type> [<value>]
JSON::array remove <array> <index>
JSON::array values <array>

JSON::array size <array>

  • Return the current number of values in the array.

JSON::array type <array> <index>

  • Return a string representing the type of the value stored at a given index in an array. The strings returned follow the same pattern as described for the ‘JSON::type’ command.

JSON::array get <array> <index> [<type>]

  • Returns the value stored at a given index of the array. When type is supplied, return a type-specific Tcl representation of the data within the JSON element (see ‘JSON::get’ return values). When type is not given, return the JSON element handle.

JSON::array set <array> <index> <type> [<value>]

  • Store a value in an array at the given index, replacing any previous value. The value is described by a type and (depending on the type) a value (see ‘JSON::set’ for more details). Return a JSON element handle for the newly created and stored value.

JSON::array insert <array> <index> <type> [<value>]

  • Insert a new value at the given index of an array, sliding all values at the index and above up by one (their indices increase by 1). If the index is the array size, the new value is appended. The array size increases by 1. The value is described by a type and (depending on the type) a value (see ‘JSON::set’ for more details). Return a JSON element handle for the newly created and inserted value.

JSON::array append <array> <type> [<value>]

  • Appends a new value to the end of an array, increasing array size by one. Equivalent to ‘JSON::array insert’ with an index equal to the size of the array. The value is described by a type and (depending on the type) a value (see ‘JSON::set’ for more details). Return a JSON element handle for the newly created and appended value.

JSON::array remove <array> <index>

  • Removes a value at the given index from an array, sliding all values at indices above the index down by one (their indices decrease by 1). The array size decreases by 1.

JSON::array values <array>

  • Returns a Tcl list of all the values stored in the array. The order is undefined.

Examples

when JSON_REQUEST {
    set rootval [JSON::root]
    set ary [JSON::get $rootval array]

    set size [JSON::array size $ary]
    set type_at_idx [JSON::array type $ary 2]
    set myint [JSON::array get $ary 1 integer]
    JSON::array set $ary 0 integer 500
    JSON::array insert $ary 5 string John
    JSON::array append $ary null
    JSON::array remove $ary 7
    set myvaluelist [JSON::array values $ary]
}