mirror of
https://github.com/json-c/json-c.git
synced 2026-04-02 20:09:06 +08:00
json_pointer: introduce json_pointer_get_internal() for internal usage
For JSON patch, we require that we get access to the parent of a JSON
object as well in order to do some operations via the API.
For example, given the object:
{
"foo": "bar",
"array", [ 1, 2, 3]
}
Using JSON pointer with the path
* '/foo' will return 'bar' of type string
* '/array/0' will return '1', of type integer
The problem is, that if we do 'json_object_put()' on any of the objects
above, this will not detach them from the parent, because there is no
information back to the parent.
One way to fix this, is to introduce links back to the parent, and have
these links be made by 'json_object_array_{put,insert}_idx()' and
'json_object_object_add{_ex}()'[1].
[1] For json_object_object_add_ex() we would need to de-constify the second
parameter, as we need to change it's internal state when being added to a
parent object. It may break some applications, but who knows.
But, since this information is needed mostly for JSON patch, another way to
address this, is to also retrieve the parent of an object via JSON pointer
and use json_object_object_del() and json_object_array_del_idx() on the
object's parent.
Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
This commit is contained in:
committed by
Eric Hawicz
parent
43d3118935
commit
5a46a3b76d
@@ -100,6 +100,18 @@ void _json_c_set_last_err(const char *err_fmt, ...);
|
||||
|
||||
extern const char *json_hex_chars;
|
||||
|
||||
struct json_pointer_get_result {
|
||||
struct json_object *parent;
|
||||
struct json_object *obj;
|
||||
union {
|
||||
const char *key;
|
||||
uint32_t index;
|
||||
} id;
|
||||
};
|
||||
|
||||
int json_pointer_get_internal(struct json_object *obj, const char *path,
|
||||
struct json_pointer_get_result *res);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user