JSON Paths
Basic dot-delimited fragment resolution
# - the root node path = new JsonPath(parser.get_root()); assert (path.get_node("#") == parser.get_root()); """ { "foo":{ "anArray":[ {"prop":44} ], "another prop":{ "baz":"A string" } } } fragment identifier resolution ------------------- ---------- # self, the root of the resource itself #foo the object referred to by the foo property #foo.another prop the object referred to by the "another prop" property of the object referred to by the "foo" property #foo.another prop.baz the string referred to by the value of "baz" property of the "another prop" property of the object referred to by the "foo" property #foo.anArray.0 the first object in the "anArray" array """
path.get_node("#foo.another prop") == Json.Object({ "baz" : "A string" });
path.get_node("#foo.another prop.baz") == Json.Node(typeof (string), "A string")); path.get_node("#foo.another prop.baz").type == typeof (string); path.get_string("#foo.another prop.baz") == "A string";
Globs
- Arrays:
""" [ { "foo" : [ 1, 1, 2, 3, 5, 8, 13 ], "bar" : true }, { "foo" : 3.14, "bar" : false } ] """ #*.foo [ [ 1, 1, 2, 3, 5, 8, 13 ], 3.14 ] #*.bar [ true, false ]
- Objects:
""" { "foo" : { "isSet" : true, "size" : [ 256, 256 ], "depth" : 8 }, "bar" : { "isSet" : false } "baz" : { "isSet" : true, "size" : [ 512, 512 ], "depth" : 16 } } """ #*.isSet [ true, false, true ] #*.size [ [ 256, 256 ], null, [ 512, 512 ] ]
API
JsonPath * json_path_new (void); void json_path_set_root (JsonPath *path, JsonNode *node); JsonNode * json_path_get_node (JsonPath *path, const gchar *str, GError **error); G_CONST_RETURN *json_path_get_string_value (JsonPath *path, const gchar *str, GError **error); gboolean json_path_get_boolean_value (JsonPath *path, const gchar *str, GError **error); gdouble json_path_get_double_value (JsonPath *path, const gchar *str, GError **error); gint64 json_path_get_int_value (JsonPath *path, const gchar *str, GError **error); gboolean json_path_get_null_value (JsonPath *path, const gchar *str, GError **error);