Functions¶
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Details¶
- Json.boxed_can_deserialize(gboxed_type, node_type)¶
- Parameters:
gboxed_type (
GObject.GType) – a boxed typenode_type (
Json.NodeType) – a node type
- Returns:
TRUEif the type can be deserialized, andFALSEotherwise- Return type:
Checks whether it is possible to deserialize a
GBoxedof typegboxed_typefrom a [struct`Json`.Node] of typenode_type.New in version 0.10.
- Json.boxed_can_serialize(gboxed_type)¶
- Parameters:
gboxed_type (
GObject.GType) – a boxed type- Returns:
TRUEif the type can be serialized, andFALSEotherwise- node_type:
the node type to which the boxed type can be serialized into
- Return type:
(
bool, node_type:Json.NodeType)
Checks whether it is possible to serialize a
GBoxedof typegboxed_typeinto a [struct`Json`.Node].The type of the node is placed inside
node_typeif the function returnsTRUE, and it’s undefined otherwise.New in version 0.10.
- Json.boxed_deserialize(gboxed_type, node)¶
- Parameters:
gboxed_type (
GObject.GType) – a boxed typenode (
Json.Node) – a node
- Returns:
the newly allocated boxed data
- Return type:
Deserializes the given [struct`Json`.Node] into a
GBoxedof the given type.New in version 0.10.
- Json.boxed_serialize(gboxed_type, boxed)¶
- Parameters:
gboxed_type (
GObject.GType) – a boxed typeboxed (
objectorNone) – a pointer to a boxed of typegboxed_type
- Returns:
a node with the serialized boxed type
- Return type:
Serializes a pointer to a
GBoxedof the given type into a [struct`Json`.Node].If the serialization is not possible, this function will return
NULL.New in version 0.10.
- Json.construct_gobject(gtype, data, length)¶
- Parameters:
gtype (
GObject.GType) – the type of the object to constructdata (
str) – a JSON data streamlength (
int) – length of the data stream (unused)
- Raises:
- Returns:
a new object instance of the given type
- Return type:
Deserializes a JSON data stream and creates an instance of the given type.
If the given type implements the [iface`Json`.Serializable] interface, it will be asked to deserialize all the JSON members into their 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.
For historical reasons, the
lengthargument is unused. The givendatamust be aNUL-terminated string.New in version 0.4.
Deprecated since version 0.10: Use [func`Json`.gobject_from_data] instead
- Json.from_string(str)¶
- Parameters:
str (
str) – a valid UTF-8 string containing JSON data- Raises:
- Returns:
the root node of the JSON tree
- Return type:
Parses the given string and returns the corresponding JSON tree.
If the string is empty, this function will return
NULL.In case of parsing error, this function returns
NULLand sets the error appropriately.New in version 1.2.
- Json.gobject_deserialize(gtype, node)¶
- Parameters:
gtype (
GObject.GType) – the type of the object to createnode (
Json.Node) – a node of typeJSON_NODE_OBJECTdescribing the object instance for the given type
- Returns:
The newly created instance
- Return type:
Creates a new
GObjectinstance of the given type, and constructs it using the members of the object in the given node.New in version 0.10.
- Json.gobject_from_data(gtype, data, length)¶
- Parameters:
gtype (
GObject.GType) – the type of the object to constructdata (
str) – a JSON data streamlength (
int) – length of the data stream, or -1 if it isNUL-terminated
- Raises:
- Returns:
a new object instance of the given type
- Return type:
Deserializes a JSON data stream and creates an instance of the given type.
If the type implements the [iface`Json`.Serializable] interface, it will be asked to deserialize all the JSON members into their 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
New in version 0.10.
- Json.gobject_serialize(gobject)¶
- Parameters:
gobject (
GObject.Object) – the object to serialize- Returns:
the newly created JSON tree
- Return type:
Creates a JSON tree representing the passed object instance.
Each member of the returned JSON object will map to a property of the object type.
The returned JSON tree will be returned as a
JsonNodewith a type ofJSON_NODE_OBJECT.New in version 0.10.
- Json.gobject_to_data(gobject)¶
- Parameters:
gobject (
GObject.Object) – the object to serialize- Returns:
a JSON data stream representing the given object
- length:
return value for the length of the buffer
- Return type:
Serializes a
GObjectinstance into a JSON data stream, iterating recursively over each property.If the given object implements the [iface`Json`.Serializable] 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.
New in version 0.10.
- Json.gvariant_deserialize(json_node, signature)¶
- Parameters:
- Raises:
- Returns:
A newly created
GVariant- Return type:
GLib.VariantorNone
Converts a JSON data structure to a
GVariant.If
signatureis notNULL, it will be used to resolve ambiguous data types.If no error occurs, the resulting
GVariantis guaranteed to conform tosignature.If
signatureis notNULLbut does not represent a validGVarianttype string,NULLis returned and theerroris set toG_IO_ERROR_INVALID_ARGUMENT.If a
signatureis provided but the JSON structure cannot be mapped to it,NULLis returned and theerroris set toG_IO_ERROR_INVALID_DATA.If
signatureisNULL, 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.
New in version 0.14.
- Json.gvariant_deserialize_data(json, length, signature)¶
- Parameters:
- Raises:
- Returns:
A newly created ``GVariant``D compliant
- Return type:
GLib.VariantorNone
Converts a JSON string to a
GVariantvalue.This function works exactly like [func`Json`.gvariant_deserialize], but takes a JSON encoded string instead.
The string is first converted to a [struct`Json`.Node] using [class`Json`.Parser], and then
json_gvariant_deserializeis called on the node.The returned variant has a floating reference that will need to be sunk by the caller code.
New in version 0.14.
- Json.gvariant_serialize(variant)¶
- Parameters:
variant (
GLib.Variant) – AGVariantto convert- Returns:
the root of the JSON data structure obtained from
variant- Return type:
Converts
variantto a JSON tree.New in version 0.14.
- Json.gvariant_serialize_data(variant)¶
- Parameters:
variant (
GLib.Variant) – AGLib.Variantto convert- Returns:
The JSON encoded string corresponding to the given variant
- length:
the length of the returned string
- Return type:
Converts variant to its JSON encoded string representation.
This is a convenience function around [func`Json`.gvariant_serialize], to obtain the JSON tree, and then [class`Json`.Generator] to stringify it.
New in version 0.14.
- Json.serialize_gobject(gobject)¶
- Parameters:
gobject (
GObject.Object) – the object to serialize- Returns:
a JSON data stream representing the given object
- length:
return value for the length of the buffer
- Return type:
Serializes a
GObjectinstance into a JSON data stream.If the object implements the [iface`Json`.Serializable] 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.
Deprecated since version 0.10: Use [func`Json`.gobject_to_data] instead
- Json.string_compare(a, b)¶
- Parameters:
- Returns:
an integer less than zero if
a < b, equal to zero ifa == b, and greater than zero ifa > b- Return type:
Check whether a and b are equal UTF-8 JSON strings and return an ordering over them in
strcmp()style.New in version 1.2.
- Json.string_equal(a, b)¶
- Parameters:
- Returns:
TRUEif a and b are equal;FALSEotherwise- Return type:
Check whether a and b are equal UTF-8 JSON strings.
New in version 1.2.
- Json.string_hash(key)¶
-
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.
New in version 1.2.
- Json.to_string(node, pretty)¶
- Parameters:
- Returns:
the string representation of the node
- Return type:
Generates a stringified JSON representation of the contents of the given
node.New in version 1.2.