]> git.ipfire.org Git - thirdparty/json-c.git/commit
json_pointer: split json_pointer_set_with_array_cb()
authorAlexandru Ardelean <ardeleanalex@gmail.com>
Fri, 23 Apr 2021 18:56:29 +0000 (21:56 +0300)
committerEric Hawicz <erh+git@nimenees.com>
Tue, 1 Aug 2023 02:17:30 +0000 (22:17 -0400)
commite4d9fbd52a56ab108630647cf7992be5c73a37a6
treed20f10155ff6e41937a19d8ab45c6bffa60772a8
parent1c38dea651447fcaf4ec5930d622a7d0e6384e43
json_pointer: split json_pointer_set_with_array_cb()

JSON patch is a bit more clear on how some array operations should be
handled. Unfortunately, handling them on a case-by-case is a bit tricky
because it's difficult to satisfy properly an 'add' operating with a 'move'
operation and the basic json_pointer_set().

With json_pointer_set{f}() we use json_object_array_put_idx() to insert a
value at a certain index.

With JSON patch:
* for the 'add' operation, we need to insert a value at a given index,
  which means shifting existing values by one to the right
  - also, we cannot allow values to be inserted/added outside the bounds of
    the array
* a 'move' operation, is described as a 'remove' and then an 'add';
  for arrays this complicates things, because when we want to a move a
  value within the array, we have to remove it first (during which the size
  of the array is reduced by one); when the size of the array is reduced by
  one, we can't add it to the last position in the array (before the
  remove)

The only sane method to handle this (after a few considerations) is to
provide a callback to the function that does the final put/insert into
the array. That way, we can do some final checks where these are needed to
handle each corner-case.

Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
json_object_private.h
json_pointer.c