aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/json.c
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2023-11-15 13:50:15 +0100
committerEgor Tensin <Egor.Tensin@gmail.com>2023-11-15 14:03:11 +0100
commit992ac5301fc8727d83017b242af2df9895eebfcc (patch)
tree4fdd21a61b54d368540d6ef65258f97473051381 /src/json.c
parentclient: print the server response (diff)
downloadcimple-992ac5301fc8727d83017b242af2df9895eebfcc.tar.gz
cimple-992ac5301fc8727d83017b242af2df9895eebfcc.zip
implement a command to list runs
Diffstat (limited to 'src/json.c')
-rw-r--r--src/json.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/json.c b/src/json.c
index 2909c74..ec555b9 100644
--- a/src/json.c
+++ b/src/json.c
@@ -6,6 +6,7 @@
*/
#include "json.h"
+#include "buf.h"
#include "log.h"
#include "net.h"
@@ -108,6 +109,28 @@ destroy_buf:
return result;
}
+int json_new_object(struct json_object **_obj)
+{
+ struct json_object *obj = json_object_new_object();
+ if (!obj) {
+ json_errno("json_object_new_object");
+ return -1;
+ }
+ *_obj = obj;
+ return 0;
+}
+
+int json_new_array(struct json_object **_arr)
+{
+ struct json_object *arr = json_object_new_array();
+ if (!arr) {
+ json_errno("json_object_new_array");
+ return -1;
+ }
+ *_arr = arr;
+ return 0;
+}
+
int json_has(const struct json_object *obj, const char *key)
{
return json_object_object_get_ex(obj, key, NULL);
@@ -254,3 +277,13 @@ int json_set_int_const_key(struct json_object *obj, const char *key, int64_t val
{
return json_set_int_internal(obj, key, value, json_const_key_flags);
}
+
+int json_append(struct json_object *arr, struct json_object *elem)
+{
+ int ret = json_object_array_add(arr, elem);
+ if (ret < 0) {
+ json_errno("json_object_array_add");
+ return ret;
+ }
+ return ret;
+}