]> git.ipfire.org Git - thirdparty/json-c.git/commit
json_pointer: introduce json_pointer_get_internal() for internal usage
authorAlexandru Ardelean <ardeleanalex@gmail.com>
Tue, 20 Apr 2021 13:23:47 +0000 (16:23 +0300)
committerEric Hawicz <erh+git@nimenees.com>
Tue, 1 Aug 2023 02:17:30 +0000 (22:17 -0400)
commit5a46a3b76d774ab3f2d884462d4bd4c382f3e835
tree474d94f083d33d1f1d8930e2c44d136aae5ebe4f
parent43d311893516aa56ef2935cb335e169d2671669c
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>
json-c.sym
json_object_private.h
json_pointer.c