src/json.c

changeset 1055
221e2e2f2c06
parent 1054
fb1076ead56f
child 1057
4e8436c3e806
--- a/src/json.c	Wed Dec 25 19:33:04 2024 +0100
+++ b/src/json.c	Thu Dec 26 18:32:05 2024 +0100
@@ -805,6 +805,16 @@
 }
 
 int cxJsonObjPut(CxJsonValue* obj, cxstring name, CxJsonValue* child) {
+    // TODO: optimize - issue #462
+    for (size_t i = 0; i < obj->value.object.values_size; i++) {
+        if (0 == cx_strcmp(name, cx_strcast(obj->value.object.values[i].name))) {
+            // free the original value
+            cxJsonValueFree(obj->value.object.values[i].value);
+            obj->value.object.values[i].value = child;
+            return 0;
+        }
+    }
+
     CxArrayReallocator value_realloc = cx_array_reallocator(obj->allocator, NULL);
     assert(obj->type == CX_JSON_OBJECT);
     cxmutstr k = cx_strdup_a(obj->allocator, name);

mercurial