diff options
author | José Bollo <jose.bollo@iot.bzh> | 2016-03-02 17:44:16 +0100 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2016-03-02 17:47:58 +0100 |
commit | 740c64f92c24da30a8636b836a21e91fcba70463 (patch) | |
tree | cc04725d3bde7c107ef745c7c63e24c75e723d34 /src/utils-json.c | |
parent | fa9948dbf66d6767a987485c24afdd15f1bab0ba (diff) |
utils-json: adds function for new array/object
Change-Id: I14168684cdfcae7ec0689eb45ab09aff82d66d22
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/utils-json.c')
-rw-r--r-- | src/utils-json.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/utils-json.c b/src/utils-json.c index 3af2a4c..eb1f90b 100644 --- a/src/utils-json.c +++ b/src/utils-json.c @@ -117,3 +117,23 @@ int j_add_integer(struct json_object *obj, const char *key, int val) return str ? j_add(obj, key, str) : (errno = ENOMEM, 0); } +struct json_object *j_add_new_array(struct json_object *obj, const char *key) +{ + struct json_object *result = json_object_new_array(); + if (result != NULL && !j_add(obj, key, result)) { + json_object_put(result); + result = NULL; + } + return result; +} + +struct json_object *j_add_new_object(struct json_object *obj, const char *key) +{ + struct json_object *result = json_object_new_object(); + if (result != NULL && !j_add(obj, key, result)) { + json_object_put(result); + result = NULL; + } + return result; +} + |