# HG changeset patch # User Mike Becker # Date 1735234325 -3600 # Node ID 221e2e2f2c06997d0c08f9f4056535192cf631ab # Parent fb1076ead56f17057f97c876452c58a03407c4e5 fix cxJsonObjPut() for existing keys issue #532 diff -r fb1076ead56f -r 221e2e2f2c06 src/json.c --- 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);