return -ENOMEM;
}
- /* if there is, but obj1 or obj2 is not json_type_object - replace it */
+ /* if both obj1 and obj2 are arrays move contents from
+ * obj1 to obj2 and replace obj1 with obj2 */
+ if (json_object_is_type(obj1_node, json_type_array) &&
+ json_object_is_type(obj2_node, json_type_array)) {
+ size_t obj2_size = json_object_array_length(obj2_node);
+ for (size_t i = 0; i < json_object_array_length(obj1_node); i++) {
+ json_object *o = json_object_array_get_idx(obj1_node, i);
+ json_object_get(o);
+ json_object_array_put_idx(obj2_node, obj2_size++, o);
+ }
+ /* obj1 will be deleted in next condition (it'll be true) */
+ }
+
+ /* if there is object with key in obj1 (obj2), but either obj1 or obj2
+ * is not json_type_object - replace it */
if (!json_object_is_type(obj1_node, json_type_object) ||
!json_object_is_type(obj2_node, json_type_object)) {