[ 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 value using signature to resolve ambiguous data types.

If no error occurs, the resulting Variant 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.

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



A Node to convert


A valid Variant type string, or null


A newly created, floating Variant compliant with signature, or null on error

Namespace: Json
Package: json-glib-1.0