mirror of
https://github.com/json-c/json-c.git
synced 2026-03-27 08:59:07 +08:00
json_object: introduce json_object_array_insert_idx() API function
The behavior of the json_object_array_put_idx() is that, if a user wants to insert an element inside a JSON array, the element will be replaced. For some cases, a user would want to insert an element into the JSON array and shift the elements to the right. For indexes that are outside the length of the current array this behaves like json_object_array_put_idx(). If a user wants to enforce that the JSON array is not expanded, then the json_object_array_length() function can be used to guard against that. The main driver for this change is JSON patch, where the 'add' operation in an array means inserting a value at a certain index and shifting everything by one. Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
This commit is contained in:
committed by
Eric Hawicz
parent
5568916eb1
commit
a86d7a8f5a
@@ -1519,6 +1519,12 @@ int json_object_array_add(struct json_object *jso, struct json_object *val)
|
||||
return array_list_add(JC_ARRAY(jso)->c_array, val);
|
||||
}
|
||||
|
||||
int json_object_array_insert_idx(struct json_object *jso, size_t idx, struct json_object *val)
|
||||
{
|
||||
assert(json_object_get_type(jso) == json_type_array);
|
||||
return array_list_insert_idx(JC_ARRAY(jso)->c_array, idx, val);
|
||||
}
|
||||
|
||||
int json_object_array_put_idx(struct json_object *jso, size_t idx, struct json_object *val)
|
||||
{
|
||||
assert(json_object_get_type(jso) == json_type_array);
|
||||
|
||||
Reference in New Issue
Block a user