From 59e224c962345fdc30e3c67aa90627ad8771becf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Bollo?= Date: Tue, 8 Nov 2016 13:01:05 +0100 Subject: [PATCH] utils-json: add facility for arrays MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: I6d536d730af71b18e78720839522b82aed63c0d4 Signed-off-by: José Bollo --- src/utils-json.c | 5 ++++- src/utils-json.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utils-json.c b/src/utils-json.c index c582837..74df9a9 100644 --- a/src/utils-json.c +++ b/src/utils-json.c @@ -95,7 +95,10 @@ int j_integer_at(struct json_object *obj, const char *key, int defval) int j_add(struct json_object *obj, const char *key, struct json_object *val) { - json_object_object_add(obj, key, val); + if (key) + json_object_object_add(obj, key, val); + else + json_object_array_add(obj, val); return 1; } diff --git a/src/utils-json.h b/src/utils-json.h index a08e8b9..3c4fee3 100644 --- a/src/utils-json.h +++ b/src/utils-json.h @@ -56,6 +56,7 @@ extern int j_integer_at(struct json_object *obj, const char *key, int defval); /* * Adds a keyed value (of type) and returns true if done or false in case of error + * when key==NULL object is an array and values are appended */ extern int j_add(struct json_object *obj, const char *key, struct json_object *val); extern int j_add_string(struct json_object *obj, const char *key, const char *val); -- 2.16.6