Class (GI Struct)

Json-1.0JsonObject

Json.Object is the representation of the object type inside JSON.

A Json.Object contains Json.Node "members", which may contain fundamental types, arrays or other objects; each member of an object is accessed using a unique string, or "name".

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

To add or overwrite a member with a given name, use Json.Object.set_member.

To extract a member with a given name, use Json.Object.get_member.

To retrieve the list of members, use Json.Object.get_members.

To retrieve the size of the object (that is, the number of members it has), use Json.Object.get_size.

Index

Constructors

Properties

$gtype: GType<Json.Object>

Methods

  • Adds a new member for the given name and value into an object.

    This function will return if the object already contains a member with the same name.

    Parameters

    • member_name: string

      the name of the member

    • node: Json.Node

      the value of the member

    Returns void

  • Retrieves a copy of the value of the given member inside an object.

    Parameters

    • member_name: string

      the name of the JSON object member to access

    Returns Json.Node

    a copy of the value for the requested object member

  • Check whether a and b are equal objects, meaning they have the same set of members, and the values of corresponding members are equal.

    Parameters

    Returns boolean

    TRUE if a and b are equal, and FALSE otherwise

  • Iterates over all members of object and calls func on each one of them.

    It is safe to change the value of a member of the oobject from within the iterator function, but it is not safe to add or remove members from the object.

    The order in which the object members are iterated is the insertion order.

    Parameters

    Returns void

  • Convenience function that retrieves the array stored in member_name of object. It is an error to specify a member_name which does not exist or which holds a non-null, non-array value.

    If member_name contains null, then this function will return NULL.

    See also: Json.Object.get_member, Json.Object.has_member

    Parameters

    • member_name: string

      the name of the member

    Returns Json.Array

    the array inside the object's member

  • Convenience function that retrieves the boolean value stored in member_name of object.

    If member_name does not exist, does not contain a scalar value, or contains null, then default_value is returned instead. If member_name contains a non-boolean, non-null scalar value, then whatever json_node_get_boolean() would return is returned.

    Parameters

    • member_name: string

      the name of the object member

    • default_value: boolean

      the value to return if member_name is not valid

    Returns boolean

    the boolean value of the object's member, or the given default

  • Convenience function that retrieves the floating point value stored in member_name of object.

    If member_name does not exist, does not contain a scalar value, or contains null, then default_value is returned instead. If member_name contains a non-double, non-null scalar value, then whatever json_node_get_double() would return is returned.

    Parameters

    • member_name: string

      the name of the object member

    • default_value: number

      the value to return if member_name is not valid

    Returns number

    the floating point value of the object's member, or the given default

  • Convenience function that retrieves the integer value stored in member_name of object.

    If member_name does not exist, does not contain a scalar value, or contains null, then default_value is returned instead. If member_name contains a non-integer, non-null scalar value, then whatever json_node_get_int() would return is returned.

    Parameters

    • member_name: string

      the name of the object member

    • default_value: number

      the value to return if member_name is not valid

    Returns number

    the integer value of the object's member, or the given default

  • Retrieves the value of the given member inside an object.

    Parameters

    • member_name: string

      the name of the JSON object member to access

    Returns Json.Node

    the value for the requested object member

  • Retrieves all the names of the members of an object.

    You can obtain the value for each member by iterating the returned list and calling Json.Object.get_member.

    Returns string[]

    the member names of the object

  • Convenience function that checks whether the value stored in member_name of object is null. It is an error to specify a member_name which does not exist.

    See also: Json.Object.get_member, Json.Object.has_member

    Parameters

    • member_name: string

      the name of the member

    Returns boolean

    TRUE if the value is null

  • Convenience function that retrieves the object stored in member_name of object. It is an error to specify a member_name which does not exist or which holds a non-null, non-object value.

    If member_name contains null, then this function will return NULL.

    See also: Json.Object.get_member, Json.Object.has_member

    Parameters

    • member_name: string

      the name of the member

    Returns Json.Object

    the object inside the object's member

  • Retrieves the number of members of a JSON object.

    Returns number

    the number of members

  • Convenience function that retrieves the string value stored in member_name of object.

    If member_name does not exist, does not contain a scalar value, or contains null, then default_value is returned instead. If member_name contains a non-string, non-null scalar value, then null is returned.

    Parameters

    • member_name: string

      the name of the object member

    • default_value: string

      the value to return if member_name is not valid

    Returns string

    the string value of the object's member, or the given default

  • Checks whether object has a member named member_name.

    Parameters

    • member_name: string

      the name of a JSON object member

    Returns boolean

    TRUE if the JSON object has the requested member

  • Calculate a hash value for the given key (a JSON object).

    The hash is calculated over the object and all its members, recursively. If the object is immutable, this is a fast operation; otherwise, it scales proportionally with the number of members in the object.

    Returns number

    hash value for key

  • Removes member_name from object, freeing its allocated resources.

    Parameters

    • member_name: string

      the name of the member to remove

    Returns void

  • Seals the object, making it immutable to further changes.

    This function will recursively seal all members of the object too.

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

    Returns void

  • Sets the value of a member inside an object.

    If the object does not have a member with the given name, a new member is created.

    If the object already has a member with the given name, the current value is overwritten with the new.

    Parameters

    • member_name: string

      the name of the member

    • node: Json.Node

      the value of the member

    Returns void

  • Releases a reference on the given object.

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

    Returns void