Class (GI Struct)

Json-1.0JsonArray

Json.Array is the representation of the array type inside JSON.

A Json.Array contains Json.Node elements, which may contain fundamental types, other arrays or objects.

Since arrays can be arbitrarily big, copying them can be expensive; for this reason, they are reference counted. You can control the lifetime of a Json.Array using Json.Array.ref and Json.Array.unref.

To append an element, use Json.Array.add_element.

To extract an element at a given index, use Json.Array.get_element.

To retrieve the entire array in list form, use Json.Array.get_elements.

To retrieve the length of the array, use Json.Array.get_length.

Index

Constructors

Properties

$gtype: GType<Json.Array>

Methods

  • Retrieves a copy of the element at the given position in the array.

    Parameters

    • index_: number

      the index of the element to retrieve

    Returns Json.Node

    a copy of the element at the given position

  • Check whether two arrays are equal.

    Equality is defined as:

    • the array have the same number of elements
    • the values of elements in corresponding positions are equal

    Parameters

    Returns boolean

    TRUE if the arrays are equal, and FALSE otherwise

  • Iterates over all elements of an array, and calls a function on each one of them.

    It is safe to change the value of an element of the array while iterating over it, but it is not safe to add or remove elements from the array.

    Parameters

    • func: ArrayForeach

      the function to be called on each element

    Returns void

  • Retrieves the element at the given position in the array.

    Parameters

    • index_: number

      the index of the element to retrieve

    Returns Json.Node

    the element at the given position

  • Retrieves the length of the given array

    Returns number

    the length of the array

  • Conveniently checks whether the element at the given position inside the array contains a null value.

    See also: Json.Array.get_element, Json.Node.is_null

    Parameters

    • index_: number

      the index of the element to retrieve

    Returns boolean

    TRUE if the element is null

  • Calculates a hash value for the given key.

    The hash is calculated over the array and all its elements, recursively.

    If the array is immutable, this is a fast operation; otherwise, it scales proportionally with the length of the array.

    Returns number

    hash value for the key

  • Removes the element at the given position inside an array.

    This function will release the reference held on the element.

    Parameters

    • index_: number

      the position of the element to be removed

    Returns void

  • Seals the given array, making it immutable to further changes.

    This function will recursively seal all elements in the array too.

    If the array is already immutable, this is a no-op.

    Returns void

  • Releases a reference on the given array.

    If the reference count reaches zero, the array is destroyed and all its allocated resources are freed.

    Returns void