JSON and GVariant
This mean that now you can obtain a JSON node tree from a GVariant value and the opposite, with a single API call. I want to thank Emmanuele for reviewing my patches promptly (they were kind of lengthy), and for the positive feedback. The new API will be available in next release 0.14.
Why do we need that, anyway?
This integration seems quite natural if you give it a thought:
- json-glib and GVariant are both general purpose data structure holders,
- with serializing/deserializing capabilities
- and both are GLib based.
How does the conversion work?
Well, as you probably know, GVariant features a data-type set that is quite richer than JSON. Thus, conversion from JSON to GVariant is an ambiguous operation. To solve this, I included an optional type signature as an argument in the API, so that when a JSON tree is converted to GVariant, the signature, if provided, is used to disambiguate the data types. This mean that if a signature is provided, the resulting GVariant is guaranteed to comply with it.
GVariant * json_gvariant_deserialize (JsonNode *json_node, const gchar *signature, GError **error);
If the signature is not provided, the conversion can still be done, and a fixed mapping is used. For detailed information on how to use the new API, you can check my build of the json-glib documentation.
I hope other people find this useful.
Trackbacks are closed.