Node
Object Hierarchy:
Description:
[ CCode ( copy_function = "g_boxed_copy" , free_function = "g_boxed_free" , type_id = "json_node_get_type ()" ) ]
[ Compact ]
public class Node
A generic container of JSON data types.
`JsonNode` can contain fundamental types (integers, booleans, floating point numbers, strings) and complex types (arrays and objects).
When parsing a JSON data stream you extract the root node and walk the node tree by retrieving the type of data contained inside the node with
the `JSON_NODE_TYPE` macro. If the node contains a fundamental type you can retrieve a copy of the `GValue` holding it with the [
method@Json.Node.get_value] function, and then use the `GValue` API to extract the data; if the node contains a complex type you can retrieve
the [struct@Json.Object] or the [struct@Json.Array] using [method@Json.Node.get_object] or [method@Json.Node.get_array] respectively, and then
retrieve the nodes they contain.
A `JsonNode` may be marked as immutable using [method@Json.Node.seal]. This marks the node and all its descendents as read-only, and means that
subsequent calls to setter functions (such as [method@Json.Node.set_array]) on them will abort as a programmer error. By marking a node tree as
immutable, it may be referenced in multiple places and its hash value cached for fast lookups, without the possibility of a value deep within
the tree changing and affecting hash values. Immutable nodes may be passed to functions which retain a reference to them without needing to take
a copy.
A `JsonNode` supports two types of memory management: `malloc`/`free` semantics, and reference counting semantics. The two may be mixed to a
limited extent: nodes may be allocated (which gives them a reference count of 1), referenced one or more times, unreferenced exactly that number
of times (using [method@Json.Node.unref]), then either unreferenced exactly once more or freed (using [method@Json.Node.free]) to destroy them.
The [method@Json.Node.free] function must not be used when a node might have a reference count not equal to 1. To this end, JSON-GLib uses [
method@Json.Node.copy] and [method@Json.Node.unref] internally.
Content:
Creation methods:
Methods:
- public Node copy ()
Copies this.
- public Array? dup_array ()
Retrieves the JSON array inside this.
- public Object? dup_object ()
Retrieves the object inside this.
- public string? dup_string ()
Gets a copy of the string value stored inside a node.
- public bool equal (Node b)
Check whether this and b
are
equal node, meaning they have the same type and same values (checked recursively).
- public void free ()
Frees the resources allocated by the node.
- public unowned Array? get_array ()
Retrieves the JSON array stored inside a node.
- public bool get_boolean ()
Gets the boolean value stored inside a node.
- public double get_double ()
Gets the double value stored inside a node.
- public int64 get_int ()
Gets the integer value stored inside a node.
- public NodeType get_node_type ()
Retrieves the type of a this.
- public unowned Object? get_object ()
Retrieves the object stored inside a node.
- public unowned Node? get_parent ()
Retrieves the parent node of the given this
.
- public unowned string? get_string ()
Gets the string value stored inside a node.
- public Value get_value ()
Retrieves a value from a node and copies into value
.
- public Type get_value_type ()
Returns the `GType` of the payload of the node.
- public uint hash ()
Calculate a hash value for the given this.
- public unowned Node init (NodeType type)
Initializes a this to a specific
type
.
- public unowned Node init_array (Array? array)
Initializes this to `JSON_NODE_ARRAY` and
sets array
into it.
- public unowned Node init_boolean (bool value)
Initializes this to `JSON_NODE_VALUE` and
sets value
into it.
- public unowned Node init_double (double value)
Initializes this to `JSON_NODE_VALUE` and
sets value
into it.
- public unowned Node init_int (int64 value)
Initializes this to `JSON_NODE_VALUE` and
sets value
into it.
- public unowned Node init_null ()
Initializes this to `JSON_NODE_NULL`.
- public unowned Node init_object (Object? object)
Initializes this to `JSON_NODE_OBJECT` and
sets object
into it.
- public unowned Node init_string (string? value)
Initializes this to `JSON_NODE_VALUE` and
sets value
into it.
- public bool is_immutable ()
Check whether the given this has been
marked as immutable by calling [method@Json.
- public bool is_null ()
Checks whether this is a `JSON_NODE_NULL`.
- public void seal ()
Seals the given node, making it immutable to further changes.
- public void set_array (Array array)
Sets array
inside this.
- public void set_boolean (bool value)
Sets value
as the boolean content of the
this, replacing any existing content.
- public void set_double (double value)
Sets value
as the double content of the
this, replacing any existing content.
- public void set_int (int64 value)
Sets value
as the integer content of the
this, replacing any existing content.
- public void set_object (Object? object)
Sets objects
inside this.
- public void set_parent (Node? parent)
Sets the parent node for the given `node`.
- public void set_string (string value)
Sets value
as the string content of the
this, replacing any existing content.
- public void set_value (Value value)
Sets a scalar value inside the given node.
- public void take_array (owned Array array)
Sets array
inside this.
- public void take_object (owned Object object)
Sets object
inside this.
- public unowned string type_name ()
Retrieves the user readable name of the data type contained by
this.