Json.Node

Fields

None

Methods

class alloc ()
class new (type)
  copy ()
  dup_array ()
  dup_object ()
  dup_string ()
  equal (b)
  free ()
  get_array ()
  get_boolean ()
  get_double ()
  get_int ()
  get_node_type ()
  get_object ()
  get_parent ()
  get_string ()
  get_value ()
  get_value_type ()
  hash ()
  init (type)
  init_array (array)
  init_boolean (value)
  init_double (value)
  init_int (value)
  init_null ()
  init_object (object)
  init_string (value)
  is_immutable ()
  is_null ()
  ref ()
  seal ()
  set_array (array)
  set_boolean (value)
  set_double (value)
  set_int (value)
  set_object (object)
  set_parent (parent)
  set_string (value)
  set_value (value)
  take_array (array)
  take_object (object)
  type_name ()
  unref ()

Details

class Json.Node

A generic container of JSON data types. The contents of the Json.Node structure are private and should only be accessed via the provided functions and never directly.

classmethod alloc()
Returns:the newly allocated Json.Node. Use Json.Node.free() to free the resources allocated by this function
Return type:Json.Node

Allocates a new Json.Node. Use Json.Node.init() and its variants to initialize the returned value.

New in version 0.16.

classmethod new(type)
Parameters:type (Json.NodeType) – a Json.NodeType
Returns:the newly created Json.Node
Return type:Json.Node

Creates a new Json.Node of type.

This is a convenience function for Json.Node.alloc() and Json.Node.init(), and it’s the equivalent of:

json_node_init (json_node_alloc (), type);

copy()
Returns:the copied Json.Node
Return type:Json.Node

Copies self. If the node contains complex data types, their reference counts are increased, regardless of whether the node is mutable or immutable.

The copy will be immutable if, and only if, self is immutable. However, there should be no need to copy an immutable node.

dup_array()
Returns:the Json.Array with its reference count increased.
Return type:Json.Array or None

Retrieves the Json.Array stored inside a Json.Node and returns it with its reference count increased by one. It is a programmer error to call this on a node which doesn’t hold an array value. Use %JSON_NODE_HOLDS_ARRAY first.

dup_object()
Returns:the Json.Object
Return type:Json.Object or None

Retrieves the Json.Object inside self. The reference count of the returned object is increased. It is a programmer error to call this on a node which doesn’t hold an object value. Use %JSON_NODE_HOLDS_OBJECT first.

dup_string()
Returns:a newly allocated string containing a copy of the Json.Node contents. Use GLib.free() to free the allocated resources
Return type:str or None

Gets a copy of the string value stored inside a Json.Node. If the node does not hold a string value, None is returned.

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

Check whether self and b are equal Json.Nodes, meaning they have the same type and same values (checked recursively). Note that integer values are compared numerically, ignoring type, so a double value 4.0 is equal to the integer value 4.

New in version 1.2.

free()

Frees the resources allocated by self.

get_array()
Returns:the Json.Array
Return type:Json.Array or None

Retrieves the Json.Array stored inside a Json.Node. It is a programmer error to call this on a node which doesn’t hold an array value. Use %JSON_NODE_HOLDS_ARRAY first.

get_boolean()
Returns:a boolean value.
Return type:bool

Gets the boolean value stored inside a Json.Node. If the node holds an integer or double value which is zero, False is returned; otherwise True is returned. If the node holds a Json.NodeType.NULL value or a value of another non-boolean type, False is returned.

get_double()
Returns:a double value.
Return type:float

Gets the double value stored inside a Json.Node. If the node holds an integer value, it is returned as a double. If the node holds a False boolean value, 0.0 is returned; otherwise a non-zero double is returned. If the node holds a Json.NodeType.NULL value or a value of another non-double type, 0.0 is returned.

get_int()
Returns:an integer value.
Return type:int

Gets the integer value stored inside a Json.Node. If the node holds a double value, its integer component is returned. If the node holds a False boolean value, 0 is returned; otherwise a non-zero integer is returned. If the node holds a Json.NodeType.NULL value or a value of another non-integer type, 0 is returned.

get_node_type()
Returns:the type of the node
Return type:Json.NodeType

Retrieves the Json.NodeType of self

New in version 0.8.

get_object()
Returns:the Json.Object
Return type:Json.Object or None

Retrieves the Json.Object stored inside a Json.Node. It is a programmer error to call this on a node which doesn’t hold an object value. Use %JSON_NODE_HOLDS_OBJECT first.

get_parent()
Returns:the parent node, or None if self is the root node
Return type:Json.Node or None

Retrieves the parent Json.Node of self.

get_string()
Returns:a string value.
Return type:str or None

Gets the string value stored inside a Json.Node. If the node does not hold a string value, None is returned.

get_value()
Returns:return location for an uninitialized value
Return type:value: GObject.Value

Retrieves a value from a Json.Node and copies into value. When done using it, call GObject.Value.unset() on the GObject.Value. It is a programmer error to call this on a node which doesn’t hold a scalar value. Use %JSON_NODE_HOLDS_VALUE first.

get_value_type()
Returns:a GObject.GType for the payload.
Return type:GObject.GType

Returns the GObject.GType of the payload of the node.

New in version 0.4.

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

Calculate a hash value for the given self (a Json.Node).

The hash is calculated over the node and its value, recursively. If the node is immutable, this is a fast operation; otherwise, it scales proportionally with the size of the node’s value (for example, with the number of members in the Json.Object if this node contains an object).

New in version 1.2.

init(type)
Parameters:type (Json.NodeType) – the type of JSON node to initialize self to
Returns:the initialized Json.Node
Return type:Json.Node

Initializes a self to a specific type.

If the node has already been initialized once, it will be reset to the given type, and any data contained will be cleared.

New in version 0.16.

init_array(array)
Parameters:array (Json.Array or None) – the Json.Array to initialize self with, or None
Returns:the initialized Json.Node
Return type:Json.Node

Initializes self to Json.NodeType.ARRAY and sets array into it.

This function will take a reference on array.

If the node has already been initialized once, it will be reset to the given type, and any data contained will be cleared.

New in version 0.16.

init_boolean(value)
Parameters:value (bool) – a boolean value
Returns:the initialized Json.Node
Return type:Json.Node

Initializes self to Json.NodeType.VALUE and sets value into it.

If the node has already been initialized once, it will be reset to the given type, and any data contained will be cleared.

New in version 0.16.

init_double(value)
Parameters:value (float) – a floating point value
Returns:the initialized Json.Node
Return type:Json.Node

Initializes self to Json.NodeType.VALUE and sets value into it.

If the node has already been initialized once, it will be reset to the given type, and any data contained will be cleared.

New in version 0.16.

init_int(value)
Parameters:value (int) – an integer
Returns:the initialized Json.Node
Return type:Json.Node

Initializes self to Json.NodeType.VALUE and sets value into it.

If the node has already been initialized once, it will be reset to the given type, and any data contained will be cleared.

New in version 0.16.

init_null()
Returns:the initialized Json.Node
Return type:Json.Node

Initializes self to Json.NodeType.NULL.

If the node has already been initialized once, it will be reset to the given type, and any data contained will be cleared.

New in version 0.16.

init_object(object)
Parameters:object (Json.Object or None) – the Json.Object to initialize self with, or None
Returns:the initialized Json.Node
Return type:Json.Node

Initializes self to Json.NodeType.OBJECT and sets object into it.

This function will take a reference on object.

If the node has already been initialized once, it will be reset to the given type, and any data contained will be cleared.

New in version 0.16.

init_string(value)
Parameters:value (str or None) – a string value
Returns:the initialized Json.Node
Return type:Json.Node

Initializes self to Json.NodeType.VALUE and sets value into it.

If the node has already been initialized once, it will be reset to the given type, and any data contained will be cleared.

New in version 0.16.

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.Node.seal() on it.

New in version 1.2.

is_null()
Returns:True if the node is null
Return type:bool

Checks whether self is a Json.NodeType.NULL.

A Json.NodeType.NULL node is not the same as a None Json.Node; a Json.NodeType.NULL represents a ‘null’ value in the JSON tree.

New in version 0.8.

ref()
Returns:a pointer to self
Return type:Json.Node

Increment the reference count of self.

New in version 1.2.

seal()

Seals the Json.Node, making it immutable to further changes. In order to be sealed, the self must have a type and value set. The value will be recursively sealed — if the node holds an object, that Json.Object will be sealed, etc.

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

New in version 1.2.

set_array(array)
Parameters:array (Json.Array) – a Json.Array

Sets array inside self and increases the Json.Array reference count.

It is an error to call this on an immutable node, or on a node which is not an array node.

set_boolean(value)
Parameters:value (bool) – a boolean value

Sets value as the boolean content of the self, replacing any existing content.

It is an error to call this on an immutable node, or on a node which is not a value node.

set_double(value)
Parameters:value (float) – a double value

Sets value as the double content of the self, replacing any existing content.

It is an error to call this on an immutable node, or on a node which is not a value node.

set_int(value)
Parameters:value (int) – an integer value

Sets value as the integer content of the self, replacing any existing content.

It is an error to call this on an immutable node, or on a node which is not a value node.

set_object(object)
Parameters:object (Json.Object or None) – a Json.Object

Sets objects inside self. The reference count of object is increased.

If object is None, the node’s existing object is cleared.

It is an error to call this on an immutable node, or on a node which is not an object node.

set_parent(parent)
Parameters:parent (Json.Node) – the parent Json.Node of self

Sets the parent Json.Node of self.

It is an error to call this with an immutable parent. self may be immutable.

New in version 0.8.

set_string(value)
Parameters:value (str) – a string value

Sets value as the string content of the self, replacing any existing content.

It is an error to call this on an immutable node, or on a node which is not a value node.

set_value(value)
Parameters:value (GObject.Value) – the GObject.Value to set

Sets value inside self. The passed GObject.Value is copied into the Json.Node.

It is an error to call this on an immutable node, or on a node which is not a value node.

take_array(array)
Parameters:array (Json.Array) – a Json.Array

Sets array into self without increasing the Json.Array reference count.

It is an error to call this on an immutable node, or a node which is not an array node.

take_object(object)
Parameters:object (Json.Object) – a Json.Object

Sets object inside self. The reference count of object is not increased.

It is an error to call this on an immutable node, or on a node which is not an object node.

type_name()
Returns:a string containing the name of the type. The returned string is owned by the node and should never be modified or freed
Return type:str

Retrieves the user readable name of the data type contained by self.

unref()

Decrement the reference count of self. If it reaches zero, the node is freed.

New in version 1.2.