[ CCode ( returns_floating_reference = true ) ]
[ Version ( since = "0.14" ) ]
public Variant? gvariant_deserialize (Node json_node, string? signature) throws Error

Converts a JSON data structure to a `GVariant`.

If `signature` is not `NULL`, it will be used 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 the `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 the `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.

Example: GVariant deserialization:

public static int main (string[] args) {

try {
// Create a Node:
// See Json.gvariant_deserialize_data
string data = """{ "a" : 3, "b" : 4 }""";
Json.Parser parser = new Json.Parser ();
parser.load_from_data (data);
Json.Node node = parser.get_root ();

// Deserialization:
Variant variant = Json.gvariant_deserialize (node, null);
print (variant.print (true));
print ("\n");
} catch (Error e) {
assert_not_reached ();

return 0;

valac --pkg json-glib-1.0 deserialization-variant.vala



the node to convert


a valid `GVariant` type string


A newly created `GVariant`

Namespace: Json
Package: json-glib-1.0