A JSON array type. The contents of the #JsonArray structure are private
and should only be accessed by the provided API
Creates a new #JsonArray.
the newly created #JsonArray
Creates a new #JsonArray with @n_elements slots already allocated.
the newly created #JsonArray
number of slots to pre-allocate
Conveniently adds an array into @array. The @array takes ownership
of the newly added #JsonArray
See also: json_array_add_element(), json_node_take_array()
a #JsonArray
a #JsonArray
Conveniently adds a boolean @value into @array
See also: json_array_add_element(), json_node_set_boolean()
a #JsonArray
a boolean value
Conveniently adds a floating point @value into @array
See also: json_array_add_element(), json_node_set_double()
a #JsonArray
a floating point value
Appends @node inside @array. The array will take ownership of the
#JsonNode.
a #JsonArray
a #JsonNode
Conveniently adds an integer @value into @array
See also: json_array_add_element(), json_node_set_int()
a #JsonArray
an integer value
Conveniently adds a null element into @array
See also: json_array_add_element(), %JSON_NODE_NULL
a #JsonArray
Conveniently adds an object into @array. The @array takes ownership
of the newly added #JsonObject
See also: json_array_add_element(), json_node_take_object()
a #JsonArray
a #JsonObject
Conveniently adds a string @value into @array
See also: json_array_add_element(), json_node_set_string()
a #JsonArray
a string value
Retrieves a copy of the #JsonNode containing the value of the
element at @index_ inside a #JsonArray
a copy of the #JsonNode at the requested
index. Use json_node_unref() when done.
a #JsonArray
the index of the element to retrieve
Check whether @a and @b are equal #JsonArrays, meaning they have the same
number of elements, and the values of elements in corresponding positions
are equal.
%TRUE if @a and @b are equal; %FALSE otherwise
a JSON array
another JSON array
Iterates over all elements of @array and calls @func on
each one of them.
It is safe to change the value of a #JsonNode of the @array
from within the iterator @func, but it is not safe to add or
remove elements from the @array.
a #JsonArray
the function to be called on each element
data to be passed to the function
Conveniently retrieves the array from the element at @index_
inside @array
See also: json_array_get_element(), json_node_get_array()
the array
a #JsonArray
the index of the element to retrieve
Conveniently retrieves the boolean value of the element at @index_
inside @array
See also: json_array_get_element(), json_node_get_boolean()
the integer value
a #JsonArray
the index of the element to retrieve
Conveniently retrieves the floating point value of the element at
@index_ inside @array
See also: json_array_get_element(), json_node_get_double()
the floating point value
a #JsonArray
the index of the element to retrieve
Retrieves the #JsonNode containing the value of the element at @index_
inside a #JsonArray.
a pointer to the #JsonNode at the requested index
a #JsonArray
the index of the element to retrieve
Gets the elements of a #JsonArray as a list of #JsonNode instances.
a #GList
containing the elements of the array. The contents of the list are
owned by the array and should never be modified or freed. Use
g_list_free() on the returned list when done using it
a #JsonArray
Conveniently retrieves the integer value of the element at @index_
inside @array
See also: json_array_get_element(), json_node_get_int()
the integer value
a #JsonArray
the index of the element to retrieve
Retrieves the length of a #JsonArray
the length of the array
a #JsonArray
Conveniently retrieves whether the element at @index_ is set to null
See also: json_array_get_element(), JSON_NODE_TYPE(), %JSON_NODE_NULL
%TRUE if the element is null
a #JsonArray
the index of the element to retrieve
Conveniently retrieves the object from the element at @index_
inside @array
See also: json_array_get_element(), json_node_get_object()
the object
a #JsonArray
the index of the element to retrieve
Conveniently retrieves the string value of the element at @index_
inside @array
See also: json_array_get_element(), json_node_get_string()
the string value; the returned string is owned by
the #JsonArray and should not be modified or freed
a #JsonArray
the index of the element to retrieve
Calculate a hash value for the given @key (a #JsonArray).
The hash is calculated over the array and all its elements, recursively. If
the array is immutable, this is a fast operation; otherwise, it scales
proportionally with the length of the array.
hash value for @key
a JSON array to hash
Check whether the given @array has been marked as immutable by calling
json_array_seal() on it.
%TRUE if the @array is immutable
a #JsonArray
Increase by one the reference count of a #JsonArray.
the passed #JsonArray, with the reference count
increased by one.
a #JsonArray
Removes the #JsonNode inside @array at @index_ freeing its allocated
resources.
a #JsonArray
the position of the element to be removed
Seals the #JsonArray, making it immutable to further changes. This will
recursively seal all elements in the array too.
If the @array is already immutable, this is a no-op.
a #JsonArray
Decreases by one the reference count of a #JsonArray. If the
reference count reaches zero, the array is destroyed and all
its allocated resources are freed.
a #JsonArray
The function to be passed to json_array_foreach_element(). You
should not add or remove elements to and from @array within
this function. It is safe to change the value of @element_node.
the iterated #JsonArray
the index of the element
a #JsonNode containing the value at @index_
data passed to the function
Deserializes the contents of the passed #JsonNode into a #GBoxed
the newly created boxed type
a #JsonNode
Serializes the passed #GBoxed and stores it inside a #JsonNode
the newly created #JsonNode
a #GBoxed
The `JsonBuilder` structure contains only private data and should be
accessed using the provided API
Creates a new #JsonBuilder. You can use this object to generate a
JSON tree and obtain the root #JsonNode.
the newly created #JsonBuilder instance
Creates a new #JsonBuilder instance with its #JsonBuilder:immutable property
set to %TRUE to create immutable output trees.
a new #JsonBuilder
If called after json_builder_set_member_name(), sets @value as member of the
most recent opened object, otherwise @value is added as element of the most
recent opened array.
See also: json_builder_add_value()
the #JsonBuilder, or %NULL if the call was inconsistent
a #JsonBuilder
the value of the member or element
If called after json_builder_set_member_name(), sets @value as member of the
most recent opened object, otherwise @value is added as element of the most
recent opened array.
See also: json_builder_add_value()
the #JsonBuilder, or %NULL if the call was inconsistent
a #JsonBuilder
the value of the member or element
If called after json_builder_set_member_name(), sets @value as member of the
most recent opened object, otherwise @value is added as element of the most
recent opened array.
See also: json_builder_add_value()
the #JsonBuilder, or %NULL if the call was inconsistent
a #JsonBuilder
the value of the member or element
If called after json_builder_set_member_name(), sets null as member of the
most recent opened object, otherwise null is added as element of the most
recent opened array.
See also: json_builder_add_value()
the #JsonBuilder, or %NULL if the call was inconsistent
a #JsonBuilder
If called after json_builder_set_member_name(), sets @value as member of the
most recent opened object, otherwise @value is added as element of the most
recent opened array.
See also: json_builder_add_value()
the #JsonBuilder, or %NULL if the call was inconsistent
a #JsonBuilder
the value of the member or element
If called after json_builder_set_member_name(), sets @node as member of the
most recent opened object, otherwise @node is added as element of the most
recent opened array.
The builder will take ownership of the #JsonNode.
the #JsonBuilder, or %NULL if the call was inconsistent
a #JsonBuilder
the value of the member or element
Opens a subarray inside the given @builder. When done adding members to
the subarray, json_builder_end_array() must be called.
Can be called for first or only if the call is associated to an object member
or an array element.
the #JsonBuilder, or %NULL if the call was inconsistent
a #JsonBuilder
Opens a subobject inside the given @builder. When done adding members to
the subobject, json_builder_end_object() must be called.
Can be called for first or only if the call is associated to an object member
or an array element.
the #JsonBuilder, or %NULL if the call was inconsistent
a #JsonBuilder
Closes the subarray inside the given @builder that was opened by the most
recent call to json_builder_begin_array().
Cannot be called after json_builder_set_member_name().
the #JsonBuilder, or %NULL if the call was inconsistent
a #JsonBuilder
Closes the subobject inside the given @builder that was opened by the most
recent call to json_builder_begin_object().
Cannot be called after json_builder_set_member_name().
the #JsonBuilder, or %NULL if the call was inconsistent
a #JsonBuilder
Returns the root of the current constructed tree, if the build is complete
(ie: all opened objects, object members and arrays are being closed).
the #JsonNode, or %NULL if the build is not complete.
Free the returned value with json_node_unref().
a #JsonBuilder
Resets the state of the @builder back to its initial state.
a #JsonBuilder
Set the name of the next member in an object. The next call must add a value,
open an object or an array.
Can be called only if the call is associated to an object.
the #JsonBuilder, or %NULL if the call was inconsistent
a #JsonBuilder
the name of the member
Whether the #JsonNode tree built by the #JsonBuilder should be immutable
when created. Making the output immutable on creation avoids the expense
of traversing it to make it immutable later.
The `JsonBuilderClass` structure contains only private data
JSON data streams generator. The contents of the #JsonGenerator structure
are private and should only be accessed via the provided API.
Creates a new #JsonGenerator. You can use this object to generate a
JSON data stream starting from a data object model composed by
#JsonNodes.
the newly created #JsonGenerator instance
Retrieves the value set using json_generator_set_indent().
the number of repetitions per indentation level
a #JsonGenerator
Retrieves the value set using json_generator_set_indent_char().
the character to be used when indenting
a #JsonGenerator
Retrieves the value set using json_generator_set_pretty().
%TRUE if the generated JSON should be pretty-printed, and
%FALSE otherwise
a #JsonGenerator
Retrieves a pointer to the root #JsonNode set using
json_generator_set_root().
a #JsonNode, or %NULL. The returned node
is owned by the #JsonGenerator and it should not be freed
a #JsonGenerator
Sets the number of repetitions for each indentation level.
a #JsonGenerator
the number of repetitions of the indentation character
that should be applied when pretty printing
Sets the character to be used when indenting
a #JsonGenerator
a Unicode character to be used when indenting
Sets whether the generated JSON should be pretty printed, using the
indentation character specified in the #JsonGenerator:indent-char
property and the spacing specified in #JsonGenerator:indent property.
a #JsonGenerator
whether the generated string should be pretty printed
Sets @node as the root of the JSON data stream to be serialized by
the #JsonGenerator.
The passed @node is copied by the generator object, so it can be
safely freed after calling this function.
a #JsonGenerator
a #JsonNode
Generates a JSON data stream from @generator and returns it as a
buffer.
a newly allocated buffer holding a JSON data stream.
Use g_free() to free the allocated resources.
a #JsonGenerator
return location for the length of the returned
buffer, or %NULL
Creates a JSON data stream and puts it inside @filename, overwriting the
current file contents. This operation is atomic.
%TRUE if saving was successful.
a #JsonGenerator
path to the target file
Outputs JSON data and streams it (synchronously) to @stream.
%TRUE if the write operation was successful, and %FALSE
on failure. In case of error, the #GError will be filled accordingly
a #JsonGenerator
a #GOutputStream
a #GCancellable, or %NULL
Number of spaces to be used to indent when pretty printing.
The character that should be used when indenting in pretty print.
Whether the output should be "pretty-printed", with indentation and
newlines. The indentation level can be controlled by using the
JsonGenerator:indent property
The root #JsonNode to be used when constructing a JSON data
stream.
#JsonGenerator class
Json major version component (e.g. 1 if %JSON_VERSION is 1.2.3)
Json micro version component (e.g. 3 if %JSON_VERSION is 1.2.3)
Json minor version component (e.g. 2 if %JSON_VERSION is 1.2.3)
A generic container of JSON data types. The contents of the #JsonNode
structure are private and should only be accessed via the provided
functions and never directly.
Allocates a new #JsonNode. Use json_node_init() and its variants
to initialize the returned value.
the newly allocated #JsonNode. Use
json_node_free() to free the resources allocated by this function
Creates a new #JsonNode of @type.
This is a convenience function for json_node_alloc() and json_node_init(),
and it's the equivalent of:
|[<!-- language="C" -->
json_node_init (json_node_alloc (), type);
]|
the newly created #JsonNode
a #JsonNodeType
Copies @node. 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, @node is immutable. However,
there should be no need to copy an immutable node.
the copied #JsonNode
a #JsonNode
Retrieves the #JsonArray stored inside a #JsonNode and returns it
with its reference count increased by one.
the #JsonArray with its reference
count increased.
a #JsonNode
Retrieves the #JsonObject inside @node. The reference count of
the returned object is increased.
the #JsonObject
a #JsonNode
Gets a copy of the string value stored inside a #JsonNode
a newly allocated string containing a copy
of the #JsonNode contents. Use g_free() to free the allocated resources
a #JsonNode of type %JSON_NODE_VALUE
Check whether @a and @b are equal #JsonNodes, 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.
%TRUE if @a and @b are equal; %FALSE otherwise
a JSON node
another JSON node
Frees the resources allocated by @node.
a #JsonNode
Retrieves the #JsonArray stored inside a #JsonNode
the #JsonArray
a #JsonNode
Gets the boolean value stored inside a #JsonNode
a boolean value.
a #JsonNode of type %JSON_NODE_VALUE
Gets the double value stored inside a #JsonNode
a double value.
a #JsonNode of type %JSON_NODE_VALUE
Gets the integer value stored inside a #JsonNode
an integer value.
a #JsonNode of type %JSON_NODE_VALUE
Retrieves the #JsonNodeType of @node
the type of the node
a #JsonNode
Retrieves the #JsonObject stored inside a #JsonNode
the #JsonObject
a #JsonNode
Retrieves the parent #JsonNode of @node.
the parent node, or %NULL if @node is
the root node
a #JsonNode
Gets the string value stored inside a #JsonNode
a string value.
a #JsonNode of type %JSON_NODE_VALUE
Retrieves a value from a #JsonNode and copies into @value. When done
using it, call g_value_unset() on the #GValue.
a #JsonNode
return location for an uninitialized value
Returns the #GType of the payload of the node.
a #GType for the payload.
a #JsonNode
Calculate a hash value for the given @key (a #JsonNode).
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 #JsonObject if this node contains an object).
hash value for @key
a JSON node to hash
Initializes a @node 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.
the initialized #JsonNode
the #JsonNode to initialize
the type of JSON node to initialize @node to
Initializes @node to %JSON_NODE_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.
the initialized #JsonNode
the #JsonNode to initialize
the #JsonArray to initialize @node with, or %NULL
Initializes @node to %JSON_NODE_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.
the initialized #JsonNode
the #JsonNode to initialize
a boolean value
Initializes @node to %JSON_NODE_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.
the initialized #JsonNode
the #JsonNode to initialize
a floating point value
Initializes @node to %JSON_NODE_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.
the initialized #JsonNode
the #JsonNode to initialize
an integer
Initializes @node to %JSON_NODE_NULL.
If the node has already been initialized once, it will be reset to
the given type, and any data contained will be cleared.
the initialized #JsonNode
the #JsonNode to initialize
Initializes @node to %JSON_NODE_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.
the initialized #JsonNode
the #JsonNode to initialize
the #JsonObject to initialize @node with, or %NULL
Initializes @node to %JSON_NODE_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.
the initialized #JsonNode
the #JsonNode to initialize
a string value
Check whether the given @node has been marked as immutable by calling
json_node_seal() on it.
%TRUE if the @node is immutable
a #JsonNode
Checks whether @node is a %JSON_NODE_NULL.
A %JSON_NODE_NULL node is not the same as a %NULL #JsonNode; a
%JSON_NODE_NULL represents a 'null' value in the JSON tree.
%TRUE if the node is null
a #JsonNode
Increment the reference count of @node.
a pointer to @node
a #JsonNode
Seals the #JsonNode, making it immutable to further changes. In order to be
sealed, the @node must have a type and value set. The value will be
recursively sealed — if the node holds an object, that #JsonObject will be
sealed, etc.
If the @node is already immutable, this is a no-op.
a #JsonNode
Sets @array inside @node and increases the #JsonArray reference count.
It is an error to call this on an immutable node.
a #JsonNode initialized to %JSON_NODE_ARRAY
a #JsonArray
Sets @value as the boolean content of the @node, replacing any existing
content.
It is an error to call this on an immutable node.
a #JsonNode of type %JSON_NODE_VALUE
a boolean value
Sets @value as the double content of the @node, replacing any existing
content.
It is an error to call this on an immutable node.
a #JsonNode of type %JSON_NODE_VALUE
a double value
Sets @value as the integer content of the @node, replacing any existing
content.
It is an error to call this on an immutable node.
a #JsonNode of type %JSON_NODE_VALUE
an integer value
Sets @objects inside @node. The reference count of @object is increased.
If @object is %NULL, the node’s existing object is cleared.
It is an error to call this on an immutable node.
a #JsonNode initialized to %JSON_NODE_OBJECT
a #JsonObject
Sets the parent #JsonNode of @node.
It is an error to call this with an immutable @parent. @node may be
immutable.
a #JsonNode
the parent #JsonNode of @node
Sets @value as the string content of the @node, replacing any existing
content.
It is an error to call this on an immutable node.
a #JsonNode initialized to %JSON_NODE_VALUE
a string value
Sets @value inside @node. The passed #GValue is copied into the #JsonNode.
It is an error to call this on an immutable node.
a #JsonNode initialized to %JSON_NODE_VALUE
the #GValue to set
Sets @array into @node without increasing the #JsonArray reference count.
It is an error to call this on an immutable node.
a #JsonNode initialized to %JSON_NODE_ARRAY
a #JsonArray
Sets @object inside @node. The reference count of @object is not increased.
It is an error to call this on an immutable node.
a #JsonNode initialized to %JSON_NODE_OBJECT
a #JsonObject
Retrieves the user readable name of the data type contained by @node.
a string containing the name of the type. The returned string
is owned by the node and should never be modified or freed
a #JsonNode
Decrement the reference count of @node. If it reaches zero, the node is
freed.
a #JsonNode
Indicates the content of a #JsonNode.
The node contains a #JsonObject
The node contains a #JsonArray
The node contains a fundamental type
Special type, for nodes containing null
A JSON object type. The contents of the #JsonObject structure are private
and should only be accessed by the provided API
Creates a new #JsonObject, an JSON object type representation.
the newly created #JsonObject
Adds a member named @member_name and containing @node into a #JsonObject.
The object will take ownership of the #JsonNode.
This function will return if the @object already contains a member
@member_name.
Use json_object_set_member() instead
a #JsonObject
the name of the member
the value of the member
Retrieves a copy of the #JsonNode containing the value of @member_name
inside a #JsonObject
a copy of the node for the requested
object member or %NULL. Use json_node_unref() when done.
a #JsonObject
the name of the JSON object member to access
Check whether @a and @b are equal #JsonObjects, meaning they have the same
set of members, and the values of corresponding members are equal.
%TRUE if @a and @b are equal; %FALSE otherwise
a JSON object
another JSON object
Iterates over all members of @object and calls @func on
each one of them.
It is safe to change the value of a #JsonNode of the @object
from within the iterator @func, but it is not safe to add or
remove members from the @object.
a #JsonObject
the function to be called on each member
data to be passed to the function
Convenience function that retrieves the array
stored in @member_name of @object
See also: json_object_get_member()
the array inside the object's member
a #JsonObject
the name of the member
Convenience function that retrieves the boolean value
stored in @member_name of @object
See also: json_object_get_member()
the boolean value of the object's member
a #JsonObject
the name of the member
Convenience function that retrieves the floating point value
stored in @member_name of @object
See also: json_object_get_member()
the floating point value of the object's member
a #JsonObject
the name of the member
Convenience function that retrieves the integer value
stored in @member_name of @object
See also: json_object_get_member()
the integer value of the object's member
a #JsonObject
the name of the member
Retrieves the #JsonNode containing the value of @member_name inside
a #JsonObject.
a pointer to the node for the requested object
member, or %NULL
a #JsonObject
the name of the JSON object member to access
Retrieves all the names of the members of a #JsonObject. You can
obtain the value for each member using json_object_get_member().
a #GList
of member names. The content of the list is owned by the #JsonObject
and should never be modified or freed. When you have finished using
the returned list, use g_list_free() to free the resources it has
allocated.
a #JsonObject
Convenience function that checks whether the value
stored in @member_name of @object is null
See also: json_object_get_member()
%TRUE if the value is null
a #JsonObject
the name of the member
Convenience function that retrieves the object
stored in @member_name of @object. It is an error to specify a @member_name
which does not exist.
See also: json_object_get_member()
the object inside the object’s
member, or %NULL if the value for the member is `null`
a #JsonObject
the name of the member
Retrieves the number of members of a #JsonObject.
the number of members
a #JsonObject
Convenience function that retrieves the string value
stored in @member_name of @object
See also: json_object_get_member()
the string value of the object's member
a #JsonObject
the name of the member
Retrieves all the values of the members of a #JsonObject.
a #GList of
#JsonNodes. The content of the list is owned by the #JsonObject
and should never be modified or freed. When you have finished using the
returned list, use g_list_free() to free the resources it has allocated.
a #JsonObject
Checks whether @object has a member named @member_name.
%TRUE if the JSON object has the requested member
a #JsonObject
the name of a JSON object member
Calculate a hash value for the given @key (a #JsonObject).
The hash is calculated over the object and all its members, recursively. If
the object is immutable, this is a fast operation; otherwise, it scales
proportionally with the number of members in the object.
hash value for @key
a JSON object to hash
Check whether the given @object has been marked as immutable by calling
json_object_seal() on it.
%TRUE if the @object is immutable
a #JsonObject
Increase by one the reference count of a #JsonObject.
the passed #JsonObject, with the reference count
increased by one.
a #JsonObject
Removes @member_name from @object, freeing its allocated resources.
a #JsonObject
the name of the member to remove
Seals the #JsonObject, making it immutable to further changes. This will
recursively seal all members of the object too.
If the @object is already immutable, this is a no-op.
a #JsonObject
Convenience function for setting an array @value of
@member_name inside @object.
The @object will take ownership of the passed #JsonArray
See also: json_object_set_member()
a #JsonObject
the name of the member
the value of the member
Convenience function for setting a boolean @value of
@member_name inside @object.
See also: json_object_set_member()
a #JsonObject
the name of the member
the value of the member
Convenience function for setting a floating point @value
of @member_name inside @object.
See also: json_object_set_member()
a #JsonObject
the name of the member
the value of the member
Convenience function for setting an integer @value of
@member_name inside @object.
See also: json_object_set_member()
a #JsonObject
the name of the member
the value of the member
Sets @node as the value of @member_name inside @object.
If @object already contains a member called @member_name then
the member's current value is overwritten. Otherwise, a new
member is added to @object.
a #JsonObject
the name of the member
the value of the member
Convenience function for setting a null @value of
@member_name inside @object.
See also: json_object_set_member()
a #JsonObject
the name of the member
Convenience function for setting an object @value of
@member_name inside @object.
The @object will take ownership of the passed #JsonObject
See also: json_object_set_member()
a #JsonObject
the name of the member
the value of the member
Convenience function for setting a string @value of
@member_name inside @object.
See also: json_object_set_member()
a #JsonObject
the name of the member
the value of the member
Decreases by one the reference count of a #JsonObject. If the
reference count reaches zero, the object is destroyed and all
its allocated resources are freed.
a #JsonObject
The function to be passed to json_object_foreach_member(). You
should not add or remove members to and from @object within
this function. It is safe to change the value of @member_node.
the iterated #JsonObject
the name of the member
a #JsonNode containing the @member_name value
data passed to the function
An iterator used to iterate over the members of a #JsonObject. This must
be allocated on the stack and initialised using json_object_iter_init().
The order in which members are returned by the iterator is undefined. The
iterator is invalidated if its #JsonObject is modified during iteration.
All the fields in the #JsonObjectIter structure are private and should
never be accessed directly.
Initialise the @iter and associate it with @object.
|[<!-- language="C" -->
JsonObjectIter iter;
const gchar *member_name;
JsonNode *member_node;
json_object_iter_init (&iter, some_object);
while (json_object_iter_next (&iter, &member_name, &member_node))
{
// Do something with @member_name and @member_node.
}
]|
an uninitialised #JsonObjectIter
the #JsonObject to iterate over
Advance @iter and retrieve the next member in the object. If the end of the
object is reached, %FALSE is returned and @member_name and @member_node are
set to invalid values. After that point, the @iter is invalid.
The order in which members are returned by the iterator is undefined. The
iterator is invalidated if its #JsonObject is modified during iteration.
%TRUE if @member_name and @member_node are valid; %FALSE if the end
of the object has been reached
a #JsonObjectIter
return
location for the member name, or %NULL to ignore
return
location for the member value, or %NULL to ignore
JSON data streams parser. The contents of the #JsonParser structure are
private and should only be accessed via the provided API.
Creates a new #JsonParser instance. You can use the #JsonParser to
load a JSON stream from either a file or a buffer and then walk the
hierarchy using the data types API.
the newly created #JsonParser. Use g_object_unref()
to release all the memory it allocates.
Creates a new #JsonParser instance with its #JsonParser:immutable property
set to %TRUE to create immutable output trees.
a new #JsonParser
Retrieves the line currently parsed, starting from 1.
This function has defined behaviour only while parsing; calling this
function from outside the signal handlers emitted by #JsonParser will
yield 0.
the currently parsed line, or 0.
a #JsonParser
Retrieves the current position inside the current line, starting
from 0.
This function has defined behaviour only while parsing; calling this
function from outside the signal handlers emitted by #JsonParser will
yield 0.
the position in the current line, or 0.
a #JsonParser
Retrieves the top level node from the parsed JSON stream.
the root #JsonNode . The returned
node is owned by the #JsonParser and should never be modified
or freed.
a #JsonParser
A JSON data stream might sometimes contain an assignment, like:
|[
var _json_data = { "member_name" : [ ...
]|
even though it would technically constitute a violation of the RFC.
#JsonParser will ignore the left hand identifier and parse the right
hand value of the assignment. #JsonParser will record, though, the
existence of the assignment in the data stream and the variable name
used.
%TRUE if there was an assignment, %FALSE otherwise. If
@variable_name is not %NULL it will be set to the name of the variable
used in the assignment. The string is owned by #JsonParser and should
never be modified or freed.
a #JsonParser
Return location for the variable
name, or %NULL
Loads a JSON stream from a buffer and parses it. You can call this function
multiple times with the same #JsonParser object, but the contents of the
parser will be destroyed each time.
%TRUE if the buffer was succesfully parser. In case
of error, @error is set accordingly and %FALSE is returned
a #JsonParser
the buffer to parse
the length of the buffer, or -1
Loads a JSON stream from the content of @filename and parses it. See
json_parser_load_from_data().
%TRUE if the file was successfully loaded and parsed.
In case of error, @error is set accordingly and %FALSE is returned
a #JsonParser
the path for the file to parse
Loads the contents of an input stream and parses them.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the @cancellable object from another thread. If the
operation was cancelled, the error %G_IO_ERROR_CANCELLED will be set
on the passed @error.
%TRUE if the data stream was successfully read and
parsed, and %FALSE otherwise
a #JsonParser
an open #GInputStream
a #GCancellable, or %NULL
Asynchronously reads the contents of @stream.
For more details, see json_parser_load_from_stream() which is the
synchronous version of this call.
When the operation is finished, @callback will be called. You should
then call json_parser_load_from_stream_finish() to get the result
of the operation.
a #JsonParser
a #GInputStream
a #GCancellable, or %NULL
a #GAsyncReadyCallback to call when the request is satisfied
the data to pass to @callback
Finishes an asynchronous stream loading started with
json_parser_load_from_stream_async().
%TRUE if the content of the stream was successfully retrieves
and parsed, and %FALSE otherwise. In case of error, the #GError will be
filled accordingly.
a #JsonParser
a #GAsyncResult
Whether the #JsonNode tree built by the #JsonParser should be immutable
when created. Making the output immutable on creation avoids the expense
of traversing it to make it immutable later.
The ::array-element signal is emitted each time the #JsonParser
has successfully parsed a single element of a #JsonArray. The
array and element index are passed to the signal handlers.
a #JsonArray
the index of the newly parsed element
The ::array-end signal is emitted each time the #JsonParser
has successfully parsed an entire #JsonArray
the parsed #JsonArray
The ::array-start signal is emitted each time the #JsonParser
starts parsing a #JsonArray
The ::error signal is emitted each time a #JsonParser encounters
an error in a JSON stream.
a pointer to the #GError
The ::object-end signal is emitted each time the #JsonParser
has successfully parsed an entire #JsonObject.
the parsed #JsonObject
The ::object-member signal is emitted each time the #JsonParser
has successfully parsed a single member of a #JsonObject. The
object and member are passed to the signal handlers.
a #JsonObject
the name of the newly parsed member
The ::object-start signal is emitted each time the #JsonParser
starts parsing a #JsonObject.
The ::parse-end signal is emitted when the parser successfully
finished parsing a JSON data stream
The ::parse-start signal is emitted when the parser began parsing
a JSON data stream.
#JsonParser class.
Error enumeration for #JsonParser
This enumeration can be extended at later date
parse error
unexpected trailing comma
expected comma
expected colon
invalid bareword
empty member name (Since: 0.16)
invalid data (Since: 0.18)
unknown error
The `JsonPath` structure is an opaque object whose members cannot be
directly accessed except through the provided API.
Creates a new #JsonPath instance.
Once created, the #JsonPath object should be used with json_path_compile()
and json_path_match().
the newly created #JsonPath instance. Use
g_object_unref() to free the allocated resources when done
Queries a JSON tree using a JSONPath expression.
This function is a simple wrapper around json_path_new(),
json_path_compile() and json_path_match(). It implicitly
creates a #JsonPath instance, compiles @expression and
matches it against the JSON tree pointed by @root.
a newly-created #JsonNode of type
%JSON_NODE_ARRAY containing an array of matching #JsonNodes.
Use json_node_unref() when done
a JSONPath expression
the root of a JSON tree
Validates and decomposes @expression.
A JSONPath expression must be compiled before calling json_path_match().
%TRUE on success; on error, @error will be set with
the %JSON_PATH_ERROR domain and a code from the #JsonPathError
enumeration, and %FALSE will be returned
a #JsonPath
a JSONPath expression
Matches the JSON tree pointed by @root using the expression compiled
into the #JsonPath.
The matching #JsonNodes will be copied into a #JsonArray and
returned wrapped in a #JsonNode.
a newly-created #JsonNode of type
%JSON_NODE_ARRAY containing an array of matching #JsonNodes.
Use json_node_unref() when done
a compiled #JsonPath
a #JsonNode
The `JsonPathClass` structure is an opaque object class whose members
cannot be directly accessed.
Error code enumeration for the %JSON_PATH_ERROR domain.
Invalid query
The `JsonReader` structure contains only private data and should
be accessed using the provided API
Creates a new #JsonReader. You can use this object to read the contents of
the JSON tree starting from @node
the newly created #JsonReader. Use g_object_unref() to
release the allocated resources when done
a #JsonNode, or %NULL
Counts the elements of the current position, if @reader is
positioned on an array
the number of elements, or -1. In case of failure
the #JsonReader is set in an error state
a #JsonReader
Counts the members of the current position, if @reader is
positioned on an object
the number of members, or -1. In case of failure
the #JsonReader is set in an error state
a #JsonReader
Moves the cursor back to the previous node after being positioned
inside an array
This function resets the error state of @reader, if any was set
a #JsonReader
Moves the cursor back to the previous node after being positioned
inside an object
This function resets the error state of @reader, if any was set
a #JsonReader
Retrieves the boolean value of the current position of @reader
the boolean value
a #JsonReader
Retrieves the floating point value of the current position of @reader
the floating point value
a #JsonReader
Retrieves the #GError currently set on @reader, if the #JsonReader
is in error state
the pointer to the error, or %NULL
a #JsonReader
Retrieves the integer value of the current position of @reader
the integer value
a #JsonReader
Retrieves the name of the current member.
the name of the member, or %NULL
a #JsonReader
Checks whether the value of the current position of @reader is 'null'
%TRUE if 'null' is set, and %FALSE otherwise
a #JsonReader
Retrieves the string value of the current position of @reader
the string value
a #JsonReader
Retrieves the #JsonNode of the current position of @reader
a #JsonNode, or %NULL. The returned node
is owned by the #JsonReader and it should not be modified or freed
directly
a #JsonReader
Checks whether the @reader is currently on an array
%TRUE if the #JsonReader is on an array, and %FALSE
otherwise
a #JsonReader
Checks whether the @reader is currently on an object
%TRUE if the #JsonReader is on an object, and %FALSE
otherwise
a #JsonReader
Checks whether the @reader is currently on a value
%TRUE if the #JsonReader is on a value, and %FALSE
otherwise
a #JsonReader
Retrieves a list of member names from the current position, if @reader
is positioned on an object.
a newly allocated, %NULL-terminated
array of strings holding the members name. Use g_strfreev() when
done.
a #JsonReader
Advances the cursor of @reader to the element @index_ of the array
or the object at the current position.
You can use the json_reader_get_value* family of functions to retrieve
the value of the element; for instance:
|[
json_reader_read_element (reader, 0);
int_value = json_reader_get_int_value (reader);
]|
After reading the value, json_reader_end_element() should be called to
reposition the cursor inside the #JsonReader, e.g.:
|[
json_reader_read_element (reader, 1);
str_value = json_reader_get_string_value (reader);
json_reader_end_element (reader);
json_reader_read_element (reader, 2);
str_value = json_reader_get_string_value (reader);
json_reader_end_element (reader);
]|
If @reader is not currently on an array or an object, or if the @index_ is
bigger than the size of the array or the object, the #JsonReader will be
put in an error state until json_reader_end_element() is called. This means
that if used conditionally, json_reader_end_element() must be called on both
code paths:
|[
if (!json_reader_read_element (reader, 1))
{
json_reader_end_element (reader);
g_set_error (error, …);
return FALSE;
}
str_value = json_reader_get_string_value (reader);
json_reader_end_element (reader);
]|
%TRUE on success, and %FALSE otherwise
a #JsonReader
the index of the element
Advances the cursor of @reader to the @member_name of the object at the
current position.
You can use the json_reader_get_value* family of functions to retrieve
the value of the member; for instance:
|[
json_reader_read_member (reader, "width");
width = json_reader_get_int_value (reader);
]|
After reading the value, json_reader_end_member() should be called to
reposition the cursor inside the #JsonReader, e.g.:
|[
json_reader_read_member (reader, "author");
author = json_reader_get_string_value (reader);
json_reader_end_member (reader);
json_reader_read_member (reader, "title");
title = json_reader_get_string_value (reader);
json_reader_end_member (reader);
]|
If @reader is not currently on an object, or if the @member_name is not
defined in the object, the #JsonReader will be put in an error state until
json_reader_end_member() is called. This means that if used conditionally,
json_reader_end_member() must be called on both code paths:
|[
if (!json_reader_read_member (reader, "title"))
{
json_reader_end_member (reader);
g_set_error (error, …);
return FALSE;
}
str_value = json_reader_get_string_value (reader);
json_reader_end_member (reader);
]|
%TRUE on success, and %FALSE otherwise
a #JsonReader
the name of the member to read
Sets the root #JsonNode to be read by @reader. The @reader will take
a copy of @root
If another #JsonNode is currently set as root, it will be replaced.
a #JsonReader
a #JsonNode
The root of the JSON tree that the #JsonReader should read.
The `JsonReaderClass` structure contains only private data
Error codes enumeration for #JsonReader errors
No array found at the current position
Index out of bounds
No object found at the current position
Member not found
No valid node found at the current position
The node at the current position does not
hold a value
The node at the current position does not
hold a value of the desired type
Asks a #JsonSerializable implementation to deserialize the
property contained inside @property_node into @value.
%TRUE if the property was successfully deserialized.
a #JsonSerializable
the name of the property
a pointer to an uninitialized #GValue
a #GParamSpec
a #JsonNode containing the serialized property
Calls the #JsonSerializableIface.find_property() implementation on
the @serializable instance. *
the #GParamSpec for the property
or %NULL if no property was found
a #JsonSerializable
the name of the property
Calls the #JsonSerializableIface.get_property() implementation
on the @serializable instance.
a #JsonSerializable
a #GParamSpec
return location for the property value
Asks a #JsonSerializable implementation to serialize a #GObject
property into a #JsonNode object.
a #JsonNode containing the serialized property
a #JsonSerializable object
the name of the property
the value of the property
a #GParamSpec
Calls the #JsonSerializableIface.set_property() implementation
on the @serializable instance.
a #JsonSerializable
a #GParamSpec
the property value to set
Calls the default implementation of the #JsonSerializable
deserialize_property() virtual function
This function can be used inside a custom implementation
of the deserialize_property() virtual function in lieu of:
|[<!-- language="C" -->
JsonSerializable *iface;
gboolean res;
iface = g_type_default_interface_peek (JSON_TYPE_SERIALIZABLE);
res = iface->deserialize_property (serializable, property_name,
value,
pspec,
property_node);
]|
%TRUE if the property was successfully deserialized.
a #JsonSerializable
the name of the property
a pointer to an uninitialized #GValue
a #GParamSpec
a #JsonNode containing the serialized property
Calls the default implementation of the #JsonSerializable
#JsonSerializableIface.serialize_property() virtual function.
This function can be used inside a custom implementation
of the #JsonSerializableIface.serialize_property() virtual
function in lieu of calling the default implementation
through g_type_default_interface_peek():
|[<!-- language="C" -->
JsonSerializable *iface;
JsonNode *node;
iface = g_type_default_interface_peek (JSON_TYPE_SERIALIZABLE);
node = iface->serialize_property (serializable, property_name,
value,
pspec);
]|
a #JsonNode containing the serialized
property
a #JsonSerializable object
the name of the property
the value of the property
a #GParamSpec
Asks a #JsonSerializable implementation to deserialize the
property contained inside @property_node into @value.
%TRUE if the property was successfully deserialized.
a #JsonSerializable
the name of the property
a pointer to an uninitialized #GValue
a #GParamSpec
a #JsonNode containing the serialized property
Calls the #JsonSerializableIface.find_property() implementation on
the @serializable instance. *
the #GParamSpec for the property
or %NULL if no property was found
a #JsonSerializable
the name of the property
Calls the #JsonSerializableIface.get_property() implementation
on the @serializable instance.
a #JsonSerializable
a #GParamSpec
return location for the property value
Calls the #JsonSerializableIface.list_properties() implementation on
the @serializable instance.
an array
of #GParamSpec. Use g_free() to free the array when done.
a #JsonSerializable
return location for the length of the array
of #GParamSpec returned by the function
Asks a #JsonSerializable implementation to serialize a #GObject
property into a #JsonNode object.
a #JsonNode containing the serialized property
a #JsonSerializable object
the name of the property
the value of the property
a #GParamSpec
Calls the #JsonSerializableIface.set_property() implementation
on the @serializable instance.
a #JsonSerializable
a #GParamSpec
the property value to set
Interface that allows serializing and deserializing #GObject instances
with properties storing complex data types. The json_serialize_gobject()
function will check if the passed #GObject implements this interface,
so it can also be used to override the default property serialization
sequence.
a #JsonNode containing the serialized property
a #JsonSerializable object
the name of the property
the value of the property
a #GParamSpec
%TRUE if the property was successfully deserialized.
a #JsonSerializable
the name of the property
a pointer to an uninitialized #GValue
a #GParamSpec
a #JsonNode containing the serialized property
the #GParamSpec for the property
or %NULL if no property was found
a #JsonSerializable
the name of the property
a #JsonSerializable
a #GParamSpec
the property value to set
a #JsonSerializable
a #GParamSpec
return location for the property value
JSON-GLib version, encoded as a string, useful for printing and
concatenation.
Checks whether it is possible to deserialize a #GBoxed of
type @gboxed_type from a #JsonNode of type @node_type
%TRUE if the type can be deserialized, %FALSE otherwise
a boxed type
a #JsonNode type
Checks whether it is possible to serialize a #GBoxed of
type @gboxed_type into a #JsonNode. The type of the
#JsonNode is placed inside @node_type if the function
returns %TRUE and it's undefined otherwise.
%TRUE if the type can be serialized,
and %FALSE otherwise.
a boxed type
the #JsonNode type to which the boxed type can be
serialized into
Deserializes @node into a #GBoxed of @gboxed_type
the newly allocated #GBoxed. Use
g_boxed_free() to release the resources allocated by this
function
a boxed type
a #JsonNode
Registers a deserialization function for a #GBoxed of type @gboxed_type
from a #JsonNode of type @node_type
a boxed type
a node type
deserialization function for @boxed_type from
a #JsonNode of type @node_type
Registers a serialization function for a #GBoxed of type @gboxed_type
to a #JsonNode of type @node_type
a boxed type
a node type
serialization function for @boxed_type into
a #JsonNode of type @node_type
Serializes @boxed, a pointer to a #GBoxed of type @gboxed_type,
into a #JsonNode
a #JsonNode with the serialization of the
boxed type, or %NULL if serialization either failed or was not possible
a boxed type
a pointer to a #GBoxed of type @gboxed_type
Deserializes a JSON data stream and creates the corresponding
#GObject class. If @gtype implements the #JsonSerializableIface
interface, it will be asked to deserialize all the JSON members
into the respective properties; otherwise, the default implementation
will be used to translate the compatible JSON native types.
Note: the JSON data stream must be an object declaration.
Use json_gobject_from_data() instead
a #GObject or %NULL
the #GType of object to construct
a JSON data stream
length of the data stream
Parses the string in @str and returns a #JsonNode representing
the JSON tree.
In case of parsing error, this function returns %NULL and sets
@error appropriately.
a #JsonNode, or %NULL
a valid UTF-8 string containing JSON data
Creates a new #GObject of type @gtype, and constructs it
using the members of the passed #JsonObject
The newly created #GObject
instance. Use g_object_unref() to free the resources
allocated by this function
the type of the #GObject to create
a #JsonNode of type %JSON_NODE_OBJECT describing the
instance of type @gtype
Deserializes a JSON data stream and creates the corresponding
#GObject class. If @gtype implements the #JsonSerializableIface
interface, it will be asked to deserialize all the JSON members
into the respective properties; otherwise, the default implementation
will be used to translate the compatible JSON native types.
Note: the JSON data stream must be an object declaration.
a #GObject or %NULL
the #GType of object to construct
a JSON data stream
length of the data stream, or -1 if it is NUL-terminated
Creates a #JsonNode representing the passed #GObject
instance. Each member of the returned JSON object will
map to a property of the #GObject
the newly created #JsonNode
of type %JSON_NODE_OBJECT. Use json_node_unref() to free
the resources allocated by this function
a #GObject
Serializes a #GObject into a JSON data stream, iterating recursively
over each property.
If @gobject implements the #JsonSerializableIface interface, it will
be asked to serialize all its properties; otherwise, the default
implementation will be use to translate the compatible types into
JSON native types.
a JSON data stream representing the passed #GObject
a #GObject
return value for the length of the buffer, or %NULL
Converts a JSON data structure to a GVariant value using @signature to
resolve ambiguous data types. If no error occurs, the resulting #GVariant
is guaranteed to conform to @signature.
If @signature is not %NULL but does not represent a valid GVariant type
string, %NULL is returned and error is set to %G_IO_ERROR_INVALID_ARGUMENT.
If a @signature is provided but the JSON structure cannot be mapped to it,
%NULL is returned and error is set to %G_IO_ERROR_INVALID_DATA.
If @signature is %NULL, the conversion is done based strictly on the types
in the JSON nodes.
The returned variant has a floating reference that will need to be sunk
by the caller code.
A newly created, floating #GVariant
compliant with @signature, or %NULL on error
A #JsonNode to convert
A valid #GVariant type string, or %NULL
Converts a JSON string to a #GVariant value. This method works exactly
like json_gvariant_deserialize(), but takes a JSON encoded string instead.
The string is first converted to a #JsonNode using #JsonParser, and then
json_gvariant_deserialize() is called.
The returned variant has a floating reference that will need to be sunk
by the caller code.
A newly created, floating #GVariant compliant
with @signature, or %NULL on error
A JSON data string
The length of @json, or -1 if %NULL-terminated
A valid #GVariant type string, or %NULL
Converts @variant to a JSON tree.
A #JsonNode representing the root of the
JSON data structure obtained from @variant
A #GVariant to convert
Converts @variant to its JSON encoded string representation. This method
is actually a helper function. It uses json_gvariant_serialize() to obtain the
JSON tree, and then #JsonGenerator to stringify it.
The JSON encoded string corresponding to
@variant
A #GVariant to convert
Return location for the length of the returned
string, or %NULL
Serializes a #GObject into a JSON data stream. If @gobject implements
the #JsonSerializableIface interface, it will be asked to serizalize all
its properties; otherwise, the default implementation will be use to
translate the compatible types into JSON native types.
Use json_gobject_to_data() instead
a JSON data stream representing the passed #GObject
a #GObject
return value for the length of the buffer, or %NULL
Check whether @a and @b are equal UTF-8 JSON strings and return an ordering
over them in strcmp() style.
an integer less than zero if @a < @b, equal to zero if @a == @b, and
greater than zero if @a > @b
a JSON string
another JSON string
Check whether @a and @b are equal UTF-8 JSON strings.
%TRUE if @a and @b are equal; %FALSE otherwise
a JSON string
another JSON string
Calculate a hash value for the given @key (a UTF-8 JSON string).
Note: Member names are compared byte-wise, without applying any Unicode
decomposition or normalisation. This is not explicitly mentioned in the JSON
standard (ECMA-404), but is assumed.
hash value for @key
a JSON string to hash
Generates a stringified JSON representation of the contents of
the passed @node.
the string representation of the #JsonNode
a #JsonNode
whether the output should be prettyfied for printing