Json.Object

Fields

None

Methods

class new ()
  add_member (member_name, node)
  dup_member (member_name)
  equal (b)
  foreach_member (func, *data)
  get_array_member (member_name)
  get_boolean_member (member_name)
  get_double_member (member_name)
  get_int_member (member_name)
  get_member (member_name)
  get_members ()
  get_null_member (member_name)
  get_object_member (member_name)
  get_size ()
  get_string_member (member_name)
  get_values ()
  has_member (member_name)
  hash ()
  is_immutable ()
  ref ()
  remove_member (member_name)
  seal ()
  set_array_member (member_name, value)
  set_boolean_member (member_name, value)
  set_double_member (member_name, value)
  set_int_member (member_name, value)
  set_member (member_name, node)
  set_null_member (member_name)
  set_object_member (member_name, value)
  set_string_member (member_name, value)
  unref ()

Details

class Json.Object

A JSON object type. The contents of the Json.Object structure are private and should only be accessed by the provided API

classmethod new()
Returns:the newly created Json.Object
Return type:Json.Object

Creates a new Json.Object, an JSON object type representation.

add_member(member_name, node)
Parameters:
  • member_name (str) – the name of the member
  • node (Json.Node) – the value of the member

Adds a member named member_name and containing node into a Json.Object. The object will take ownership of the Json.Node.

This function will return if the self already contains a member member_name.

Deprecated since version 0.8: Use Json.Object.set_member() instead

dup_member(member_name)
Parameters:member_name (str) – the name of the JSON object member to access
Returns:a copy of the node for the requested object member or None. Use Json.Node.unref() when done.
Return type:Json.Node or None

Retrieves a copy of the Json.Node containing the value of member_name inside a Json.Object

New in version 0.6.

equal(b)
Parameters:b (Json.Object) – another JSON object
Returns:True if self and b are equal; False otherwise
Return type:bool

Check whether self and b are equal Json.Objects, meaning they have the same set of members, and the values of corresponding members are equal.

New in version 1.2.

foreach_member(func, *data)
Parameters:

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

It is safe to change the value of a Json.Node of the self from within the iterator func, but it is not safe to add or remove members from the self.

New in version 0.8.

get_array_member(member_name)
Parameters:member_name (str) – the name of the member
Returns:the array inside the object’s member
Return type:Json.Array

Convenience function that retrieves the array stored in member_name of self

See also: Json.Object.get_member()

New in version 0.8.

get_boolean_member(member_name)
Parameters:member_name (str) – the name of the member
Returns:the boolean value of the object’s member
Return type:bool

Convenience function that retrieves the boolean value stored in member_name of self

See also: Json.Object.get_member()

New in version 0.8.

get_double_member(member_name)
Parameters:member_name (str) – the name of the member
Returns:the floating point value of the object’s member
Return type:float

Convenience function that retrieves the floating point value stored in member_name of self

See also: Json.Object.get_member()

New in version 0.8.

get_int_member(member_name)
Parameters:member_name (str) – the name of the member
Returns:the integer value of the object’s member
Return type:int

Convenience function that retrieves the integer value stored in member_name of self

See also: Json.Object.get_member()

New in version 0.8.

get_member(member_name)
Parameters:member_name (str) – the name of the JSON object member to access
Returns:a pointer to the node for the requested object member, or None
Return type:Json.Node or None

Retrieves the Json.Node containing the value of member_name inside a Json.Object.

get_members()
Returns:a GLib.List of member names, or None. The content of the list is owned by the Json.Object and should never be modified or freed. When you have finished using the returned list, use g_list_free() to free the resources it has allocated.
Return type:[str] or None

Retrieves all the names of the members of a Json.Object. You can obtain the value for each member using Json.Object.get_member().

get_null_member(member_name)
Parameters:member_name (str) – the name of the member
Returns:True if the value is null
Return type:bool

Convenience function that checks whether the value stored in member_name of self is null

See also: Json.Object.get_member()

New in version 0.8.

get_object_member(member_name)
Parameters:member_name (str) – the name of the member
Returns:the object inside the object’s member, or None if the value for the member is null
Return type:Json.Object or None

Convenience function that retrieves the object stored in member_name of self. It is an error to specify a member_name which does not exist.

See also: Json.Object.get_member()

New in version 0.8.

get_size()
Returns:the number of members
Return type:int

Retrieves the number of members of a Json.Object.

get_string_member(member_name)
Parameters:member_name (str) – the name of the member
Returns:the string value of the object’s member
Return type:str

Convenience function that retrieves the string value stored in member_name of self

See also: Json.Object.get_member()

New in version 0.8.

get_values()
Returns:a GLib.List of Json.Nodes, or None. The content of the list is owned by the Json.Object and should never be modified or freed. When you have finished using the returned list, use g_list_free() to free the resources it has allocated.
Return type:[Json.Node] or None

Retrieves all the values of the members of a Json.Object.

has_member(member_name)
Parameters:member_name (str) – the name of a JSON object member
Returns:True if the JSON object has the requested member
Return type:bool

Checks whether self has a member named member_name.

hash()
Returns:hash value for self
Return type:int

Calculate a hash value for the given self (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.

New in version 1.2.

is_immutable()
Returns:True if the self is immutable
Return type:bool

Check whether the given self has been marked as immutable by calling Json.Object.seal() on it.

New in version 1.2.

ref()
Returns:the passed Json.Object, with the reference count increased by one.
Return type:Json.Object

Increase by one the reference count of a Json.Object.

remove_member(member_name)
Parameters:member_name (str) – the name of the member to remove

Removes member_name from self, freeing its allocated resources.

seal()

Seals the Json.Object, making it immutable to further changes. This will recursively seal all members of the object too.

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

New in version 1.2.

set_array_member(member_name, value)
Parameters:
  • member_name (str) – the name of the member
  • value (Json.Array) – the value of the member

Convenience function for setting an array value of member_name inside self.

The self will take ownership of the passed Json.Array

See also: Json.Object.set_member()

New in version 0.8.

set_boolean_member(member_name, value)
Parameters:
  • member_name (str) – the name of the member
  • value (bool) – the value of the member

Convenience function for setting a boolean value of member_name inside self.

See also: Json.Object.set_member()

New in version 0.8.

set_double_member(member_name, value)
Parameters:
  • member_name (str) – the name of the member
  • value (float) – the value of the member

Convenience function for setting a floating point value of member_name inside self.

See also: Json.Object.set_member()

New in version 0.8.

set_int_member(member_name, value)
Parameters:
  • member_name (str) – the name of the member
  • value (int) – the value of the member

Convenience function for setting an integer value of member_name inside self.

See also: Json.Object.set_member()

New in version 0.8.

set_member(member_name, node)
Parameters:
  • member_name (str) – the name of the member
  • node (Json.Node) – the value of the member

Sets node as the value of member_name inside self.

If self already contains a member called member_name then the member’s current value is overwritten. Otherwise, a new member is added to self.

New in version 0.8.

set_null_member(member_name)
Parameters:member_name (str) – the name of the member

Convenience function for setting a null value of member_name inside self.

See also: Json.Object.set_member()

New in version 0.8.

set_object_member(member_name, value)
Parameters:
  • member_name (str) – the name of the member
  • value (Json.Object) – the value of the member

Convenience function for setting an object value of member_name inside self.

The self will take ownership of the passed Json.Object

See also: Json.Object.set_member()

New in version 0.8.

set_string_member(member_name, value)
Parameters:
  • member_name (str) – the name of the member
  • value (str) – the value of the member

Convenience function for setting a string value of member_name inside self.

See also: Json.Object.set_member()

New in version 0.8.

unref()

Decreases by one the reference count of a Json.Object. If the reference count reaches zero, the object is destroyed and all its allocated resources are freed.