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:
TRUE
if the type can be deserialized, andFALSE
otherwise- Return type:
Checks whether it is possible to deserialize a
GBoxed
of typegboxed_type
from 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:
TRUE
if the type can be serialized, andFALSE
otherwise- 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
GBoxed
of typegboxed_type
into a [struct`Json`.Node].The type of the node is placed inside
node_type
if 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
GBoxed
of the given type.New in version 0.10.
- Json.boxed_serialize(gboxed_type, boxed)¶
- Parameters:
gboxed_type (
GObject.GType
) – a boxed typeboxed (
object
orNone
) – a pointer to a boxed of typegboxed_type
- Returns:
a node with the serialized boxed type
- Return type:
Serializes a pointer to a
GBoxed
of 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
length
argument is unused. The givendata
must 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
NULL
and 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_OBJECT
describing the object instance for the given type
- Returns:
The newly created instance
- Return type:
Creates a new
GObject
instance 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
JsonNode
with 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
GObject
instance 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.Variant
orNone
Converts a JSON data structure to a
GVariant
.If
signature
is notNULL
, it will be used to resolve ambiguous data types.If no error occurs, the resulting
GVariant
is guaranteed to conform tosignature
.If
signature
is notNULL
but does not represent a validGVariant
type string,NULL
is returned and theerror
is set toG_IO_ERROR_INVALID_ARGUMENT
.If a
signature
is provided but the JSON structure cannot be mapped to it,NULL
is returned and theerror
is set toG_IO_ERROR_INVALID_DATA
.If
signature
isNULL
, 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.Variant
orNone
Converts a JSON string to a
GVariant
value.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_deserialize
is 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
) – AGVariant
to convert- Returns:
the root of the JSON data structure obtained from
variant
- Return type:
Converts
variant
to a JSON tree.New in version 0.14.
- Json.gvariant_serialize_data(variant)¶
- Parameters:
variant (
GLib.Variant
) – AGLib.Variant
to 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
GObject
instance 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:
TRUE
if a and b are equal;FALSE
otherwise- 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.