json.node

Module for [Node] class

class Node

Types 1

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.ObjectWrap 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.

Methods
void * _cPtr(Flag!"Dup" dup = No.Dup) nothrow
GType _getGType() static nothrow
GType _gType() @property nothrow
Node self() nothrowReturns `this`, for use in `with` statements.
json.node.Node alloc() static nothrowAllocates a new, uninitialized node.
json.node.Node copy() nothrowCopies node.
json.array.Array dupArray() nothrowRetrieves the JSON array inside node.
json.object.ObjectWrap dupObject() nothrowRetrieves the object inside node.
string dupString() nothrowGets a copy of the string value stored inside a node.
bool equal(json.node.Node b) nothrowCheck whether `a` and `b` are equal node, meaning they have the same type and same values (checked recursively).
json.array.Array getArray() nothrowRetrieves the JSON array stored inside a node.
bool getBoolean() nothrowGets the boolean value stored inside a node.
double getDouble() nothrowGets the double value stored inside a node.
long getInt() nothrowGets the integer value stored inside a node.
json.types.NodeType getNodeType() nothrowRetrieves the type of a node. Returns: the type of the node
json.object.ObjectWrap getObject() nothrowRetrieves the object stored inside a node.
json.node.Node getParent() nothrowRetrieves the parent node of the given node. Returns: the parent node, or `NULL` if node is the root node
string getString() nothrowGets the string value stored inside a node.
void getValue(out gobject.value.Value value) nothrowRetrieves a value from a node and copies into value.
gobject.types.GType getValueType() nothrowReturns the `GType` of the payload of the node.
uint hash() nothrowCalculate a hash value for the given key.
json.node.Node init_(json.types.NodeType type) nothrowInitializes a node to a specific type.
json.node.Node initArray(json.array.Array array = null) nothrowInitializes node to [json.types.NodeType.Array] and sets array into it.
json.node.Node initBoolean(bool value) nothrowInitializes node to [json.types.NodeType.Value] and sets value into it.
json.node.Node initDouble(double value) nothrowInitializes node to [json.types.NodeType.Value] and sets value into it.
json.node.Node initInt(long value) nothrowInitializes node to [json.types.NodeType.Value] and sets value into it.
json.node.Node initNull() nothrowInitializes node to [json.types.NodeType.Null].
json.node.Node initObject(json.object.ObjectWrap object = null) nothrowInitializes node to [json.types.NodeType.Object] and sets object into it.
json.node.Node initString(string value = null) nothrowInitializes node to [json.types.NodeType.Value] and sets value into it.
bool isImmutable() nothrowCheck whether the given node has been marked as immutable by calling [json.node.Node.seal] on it. Returns: `TRUE` if the node is immutable
bool isNull() nothrowChecks whether node is a [json.types.NodeType.Null].
void seal() nothrowSeals the given node, making it immutable to further changes.
void setArray(json.array.Array array) nothrowSets array inside node.
void setBoolean(bool value) nothrowSets value as the boolean content of the node, replacing any existing content.
void setDouble(double value) nothrowSets value as the double content of the node, replacing any existing content.
void setInt(long value) nothrowSets value as the integer content of the node, replacing any existing content.
void setObject(json.object.ObjectWrap object = null) nothrowSets objects inside node.
void setParent(json.node.Node parent = null) nothrowSets the parent node for the given `node`.
void setString(string value) nothrowSets value as the string content of the node, replacing any existing content.
void setValue(gobject.value.Value value) nothrowSets a scalar value inside the given node.
void takeArray(json.array.Array array) nothrowSets array inside node.
void takeObject(json.object.ObjectWrap object) nothrowSets object inside node.
string typeName() nothrowRetrieves the user readable name of the data type contained by node.
Constructors
this(void * ptr, Flag!"Take" take)
this(json.types.NodeType type)Creates a new node holding the given type.