Node

A generic container of JSON data types.

json.node.Node 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 gobject.value.Value holding it with the json.node.Node.getValue function, and then use the gobject.value.Value API to extract the data; if the node contains a complex type you can retrieve the json.object.ObjectJson or the json.array.Array using json.node.Node.getObject or json.node.Node.getArray respectively, and then retrieve the nodes they contain.

A json.node.Node may be marked as immutable using json.node.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.Node.setArray) 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 json.node.Node 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.Node.unref), then either unreferenced exactly once more or freed (using json.node.Node.free) to destroy them. The json.node.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.Node.copy and json.node.Node.unref internally.

Constructors

this
this(json.types.NodeType type)

Creates a new node holding the given type.

Members

Functions

copy
json.node.Node copy()

Copies node.

dupArray
json.array.Array dupArray()

Retrieves the JSON array inside node.

dupObject
json.object.ObjectJson dupObject()

Retrieves the object inside node.

dupString
string dupString()

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

equal
bool equal(json.node.Node b)

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

getArray
json.array.Array getArray()

Retrieves the JSON array stored inside a node.

getBoolean
bool getBoolean()

Gets the boolean value stored inside a node.

getDouble
double getDouble()

Gets the double value stored inside a node.

getInt
long getInt()

Gets the integer value stored inside a node.

getNodeType
json.types.NodeType getNodeType()

Retrieves the type of a node.

getObject
json.object.ObjectJson getObject()

Retrieves the object stored inside a node.

getParent
json.node.Node getParent()

Retrieves the parent node of the given node.

getString
string getString()

Gets the string value stored inside a node.

getValue
void getValue(gobject.value.Value value)

Retrieves a value from a node and copies into value.

getValueType
gobject.types.GType getValueType()

Returns the gobject.types.TYPE_FLAG_RESERVED_ID_BIT of the payload of the node.

hash
uint hash()

Calculate a hash value for the given key.

initArray
json.node.Node initArray(json.array.Array array)

Initializes node to json.types.NodeType.Array and sets array into it.

initBoolean
json.node.Node initBoolean(bool value)

Initializes node to json.types.NodeType.Value and sets value into it.

initDouble
json.node.Node initDouble(double value)

Initializes node to json.types.NodeType.Value and sets value into it.

initInt
json.node.Node initInt(long value)

Initializes node to json.types.NodeType.Value and sets value into it.

initNull
json.node.Node initNull()

Initializes node to json.types.NodeType.Null.

initObject
json.node.Node initObject(json.object.ObjectJson object)

Initializes node to json.types.NodeType.Object and sets object into it.

initString
json.node.Node initString(string value)

Initializes node to json.types.NodeType.Value and sets value into it.

init_
json.node.Node init_(json.types.NodeType type)

Initializes a node to a specific type.

isImmutable
bool isImmutable()

Check whether the given node has been marked as immutable by calling json.node.Node.seal on it.

isNull
bool isNull()

Checks whether node is a json.types.NodeType.Null.

seal
void seal()

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

setArray
void setArray(json.array.Array array)

Sets array inside node.

setBoolean
void setBoolean(bool value)

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

setDouble
void setDouble(double value)

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

setInt
void setInt(long value)

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

setObject
void setObject(json.object.ObjectJson object)

Sets objects inside node.

setParent
void setParent(json.node.Node parent)

Sets the parent node for the given node.

setString
void setString(string value)

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

setValue
void setValue(gobject.value.Value value)

Sets a scalar value inside the given node.

takeArray
void takeArray(json.array.Array array)

Sets array inside node.

takeObject
void takeObject(json.object.ObjectJson object)

Sets object inside node.

typeName
string typeName()

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

Static functions

alloc
json.node.Node alloc()

Allocates a new, uninitialized node.

Inherited Members

From Boxed

cInstancePtr
void* cInstancePtr;

Pointer to the C boxed value

getType
GType getType()

Get the GType of this boxed type.

gType
GType gType [@property getter]

Boxed GType property.

self
Boxed self()

Convenience method to return this cast to a type. For use in D with statements.

copy_
void* copy_()

Make a copy of the wrapped C boxed data.

boxedCopy
void* boxedCopy(void* cBoxed)

Copy a C boxed value using g_boxed_copy.

boxedFree
void boxedFree(void* cBoxed)

Free a C boxed value using g_boxed_free.