Functions

  boxed_can_deserialize (gboxed_type, node_type)
  boxed_can_serialize (gboxed_type)
  boxed_deserialize (gboxed_type, node)
  boxed_serialize (gboxed_type, boxed)
  construct_gobject (gtype, data, length)
  from_string (str)
  gobject_deserialize (gtype, node)
  gobject_from_data (gtype, data, length)
  gobject_serialize (gobject)
  gobject_to_data (gobject)
  gvariant_deserialize (json_node, signature)
  gvariant_deserialize_data (json, length, signature)
  gvariant_serialize (variant)
  gvariant_serialize_data (variant)
  parser_error_quark ()
  path_error_quark ()
  reader_error_quark ()
  serialize_gobject (gobject)
  string_compare (a, b)
  string_equal (a, b)
  string_hash (key)
  to_string (node, pretty)

Details

Json.boxed_can_deserialize(gboxed_type, node_type)
Parameters:
Returns:

True if the type can be deserialized, False otherwise

Return type:

bool

Checks whether it is possible to deserialize a GObject.GBoxed of type gboxed_type from a Json.Node of type node_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, and False otherwise.
node_type:the Json.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 GObject.GBoxed of type gboxed_type into a Json.Node. The type of the Json.Node is placed inside node_type if the function returns True and it’s undefined otherwise.

New in version 0.10.

Json.boxed_deserialize(gboxed_type, node)
Parameters:
Returns:

the newly allocated GObject.GBoxed. Use GObject.boxed_free() to release the resources allocated by this function

Return type:

object or None

Deserializes node into a GObject.GBoxed of gboxed_type

New in version 0.10.

Json.boxed_serialize(gboxed_type, boxed)
Parameters:
Returns:

a Json.Node with the serialization of the boxed type, or None if serialization either failed or was not possible

Return type:

Json.Node or None

Serializes boxed, a pointer to a GObject.GBoxed of type gboxed_type, into a Json.Node

New in version 0.10.

Json.construct_gobject(gtype, data, length)
Parameters:
Raises:

GLib.Error

Returns:

a GObject.Object or None

Return type:

GObject.Object

Deserializes a JSON data stream and creates the corresponding GObject.Object class. If gtype implements the Json.SerializableIface 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.

New in version 0.4.

Deprecated since version 0.10: Use Json.gobject_from_data() instead

Json.from_string(str)
Parameters:str (str) – a valid UTF-8 string containing JSON data
Raises:GLib.Error
Returns:a Json.Node, or None
Return type:Json.Node

Parses the string in str and returns a Json.Node representing the JSON tree.

In case of parsing error, this function returns None and sets error appropriately.

New in version 1.2.

Json.gobject_deserialize(gtype, node)
Parameters:
Returns:

The newly created GObject.Object instance. Use GObject.Object.unref() to free the resources allocated by this function

Return type:

GObject.Object

Creates a new GObject.Object of type gtype, and constructs it using the members of the passed Json.Object

New in version 0.10.

Json.gobject_from_data(gtype, data, length)
Parameters:
  • gtype (GObject.GType) – the GObject.GType of object to construct
  • data (str) – a JSON data stream
  • length (int) – length of the data stream, or -1 if it is NUL-terminated
Raises:

GLib.Error

Returns:

a GObject.Object or None

Return type:

GObject.Object

Deserializes a JSON data stream and creates the corresponding GObject.Object class. If gtype implements the Json.SerializableIface 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.

New in version 0.10.

Json.gobject_serialize(gobject)
Parameters:gobject (GObject.Object) – a GObject.Object
Returns:the newly created Json.Node of type Json.NodeType.OBJECT. Use Json.Node.unref() to free the resources allocated by this function
Return type:Json.Node

Creates a Json.Node representing the passed GObject.Object instance. Each member of the returned JSON object will map to a property of the GObject.Object

New in version 0.10.

Json.gobject_to_data(gobject)
Parameters:gobject (GObject.Object) – a GObject.Object
Returns:a JSON data stream representing the passed GObject.Object
length:return value for the length of the buffer, or None
Return type:(str, length: int)

Serializes a GObject.Object into a JSON data stream, iterating recursively over each property.

If gobject implements the Json.SerializableIface 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:

GLib.Error

Returns:

A newly created, floating GLib.Variant compliant with signature, or None on error

Return type:

GLib.Variant

Converts a JSON data structure to a GLib.Variant value using signature to resolve ambiguous data types. If no error occurs, the resulting GLib.Variant is guaranteed to conform to signature.

If signature is not None but does not represent a valid GLib.Variant type string, None is returned and error is set to Gio.IOErrorEnum.INVALID_ARGUMENT. If a signature is provided but the JSON structure cannot be mapped to it, None is returned and error is set to Gio.IOErrorEnum.INVALID_DATA. If signature is None, 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:
  • json (str) – A JSON data string
  • length (int) – The length of json, or -1 if None-terminated
  • signature (str or None) – A valid GLib.Variant type string, or None
Raises:

GLib.Error

Returns:

A newly created, floating GLib.Variant compliant with signature, or None on error

Return type:

GLib.Variant

Converts a JSON string to a GLib.Variant value. This method works exactly like Json.gvariant_deserialize(), but takes a JSON encoded string instead. The string is first converted to a Json.Node using Json.Parser, and then Json.gvariant_deserialize() is called.

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) – A GLib.Variant to convert
Returns:A Json.Node representing the root of the JSON data structure obtained from variant
Return type:Json.Node

Converts variant to a JSON tree.

New in version 0.14.

Json.gvariant_serialize_data(variant)
Parameters:variant (GLib.Variant) – A GLib.Variant to convert
Returns:The JSON encoded string corresponding to variant
length:Return location for the length of the returned string, or None
Return type:(str, length: int)

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 Json.Generator to stringify it.

New in version 0.14.

Json.parser_error_quark()
Return type:int
Json.path_error_quark()
Return type:int
Json.reader_error_quark()
Return type:int
Json.serialize_gobject(gobject)
Parameters:gobject (GObject.Object) – a GObject.Object
Returns:a JSON data stream representing the passed GObject.Object
length:return value for the length of the buffer, or None
Return type:(str, length: int)

Serializes a GObject.Object into a JSON data stream. If gobject implements the Json.SerializableIface 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 Json.gobject_to_data() instead

Json.string_compare(a, b)
Parameters:
  • a (str) – a JSON string
  • b (str) – another JSON string
Returns:

an integer less than zero if a < b, equal to zero if a == b, and greater than zero if a > b

Return type:

int

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:
  • a (str) – a JSON string
  • b (str) – another JSON string
Returns:

True if a and b are equal; False otherwise

Return type:

bool

Check whether a and b are equal UTF-8 JSON strings.

New in version 1.2.

Json.string_hash(key)
Parameters:key (str) – a JSON string to hash
Returns:hash value for key
Return type:int

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 Json.Node

Return type:

str

Generates a stringified JSON representation of the contents of the passed node.

New in version 1.2.