diff --git a/src/jansson.h b/src/jansson.h index ee60794..fe283cc 100644 --- a/src/jansson.h +++ b/src/jansson.h @@ -139,6 +139,7 @@ int json_object_clear(json_t *object); int json_object_update(json_t *object, json_t *other); int json_object_update_existing(json_t *object, json_t *other); int json_object_update_missing(json_t *object, json_t *other); +int json_object_update_missing_incref(json_t *object, json_t *other); void *json_object_iter(json_t *object); void *json_object_iter_at(json_t *object, const char *key); void *json_object_key_to_iter(const char *key); diff --git a/src/value.c b/src/value.c index 2010605..c09faaf 100644 --- a/src/value.c +++ b/src/value.c @@ -209,6 +209,22 @@ int json_object_update_missing(json_t *object, json_t *other) return 0; } +int json_object_update_missing_incref(json_t *object, json_t *other) +{ + const char *key; + json_t *value; + + if(!json_is_object(object) || !json_is_object(other)) + return -1; + + json_object_foreach(other, key, value) { + if(!json_object_get(object, key)) + json_object_set_nocheck(object, key, json_incref(value)); + } + + return 0; +} + void *json_object_iter(json_t *json) { json_object_t *object;