Struct

JsonNode

Description [src]

struct JsonNode {
  /* No available fields */
}

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 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 JsonObject or the JsonArray using json_node_get_object() or json_node_get_array() respectively, and then retrieve the nodes they contain.

A JsonNode may be marked as immutable using json_node_seal(). This marks the node and all its descendents as read-only, and means that subsequent calls to setter functions (such as 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 json_node_unref()), then either unreferenced exactly once more or freed (using json_node_free()) to destroy them. The 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 json_node_copy() and json_node_unref() internally.

Constructors

json_node_alloc

Allocates a new, uninitialized node.

since: 0.16

json_node_new

Creates a new node holding the given type.

Instance methods

json_node_copy

Copies node.

json_node_dup_array

Retrieves the JSON array inside node.

json_node_dup_object

Retrieves the object inside node.

json_node_dup_string

Gets a copy of the string value stored inside a node.

json_node_equal

Check whether a and b are equal node, meaning they have the same type and same values (checked recursively).

since: 1.2

json_node_free

Frees the resources allocated by the node.

json_node_get_array

Retrieves the JSON array stored inside a node.

json_node_get_boolean

Gets the boolean value stored inside a node.

json_node_get_double

Gets the double value stored inside a node.

json_node_get_int

Gets the integer value stored inside a node.

json_node_get_node_type

Retrieves the type of a node.

since: 0.8

json_node_get_object

Retrieves the object stored inside a node.

json_node_get_parent

Retrieves the parent node of the given node.

json_node_get_string

Gets the string value stored inside a node.

json_node_get_value

Retrieves a value from a node and copies into value.

json_node_get_value_type

Returns the GType of the payload of the node.

since: 0.4

json_node_hash

Calculate a hash value for the given key.

since: 1.2

json_node_init

Initializes a node to a specific type.

since: 0.16

json_node_init_array

Initializes node to JSON_NODE_ARRAY and sets array into it.

since: 0.16

json_node_init_boolean

Initializes node to JSON_NODE_VALUE and sets value into it.

since: 0.16

json_node_init_double

Initializes node to JSON_NODE_VALUE and sets value into it.

since: 0.16

json_node_init_int

Initializes node to JSON_NODE_VALUE and sets value into it.

since: 0.16

json_node_init_null

Initializes node to JSON_NODE_NULL.

since: 0.16

json_node_init_object

Initializes node to JSON_NODE_OBJECT and sets object into it.

since: 0.16

json_node_init_string

Initializes node to JSON_NODE_VALUE and sets value into it.

since: 0.16

json_node_is_immutable

Check whether the given node has been marked as immutable by calling json_node_seal() on it.

since: 1.2

json_node_is_null

Checks whether node is a JSON_NODE_NULL.

since: 0.8

json_node_ref

Increments the reference count of node.

since: 1.2

json_node_seal

Seals the given node, making it immutable to further changes.

since: 1.2

json_node_set_array

Sets array inside node.

json_node_set_boolean

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

json_node_set_double

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

json_node_set_int

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

json_node_set_object

Sets objects inside node.

json_node_set_parent

Sets the parent node for the given node.

since: 0.8

json_node_set_string

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

json_node_set_value

Sets a scalar value inside the given node.

json_node_take_array

Sets array inside node.

json_node_take_object

Sets object inside node.

json_node_type_name

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

json_node_unref

Decrements the reference count of node.

since: 1.2