diff options
author | Jo-Philipp Wich <jo@mein.io> | 2020-11-16 13:06:59 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-11-16 13:06:59 +0100 |
commit | 181fde5208efa0d45126327dd0c4197e1a63fd90 (patch) | |
tree | 73db9956175a741a9056ef086c0e616d6bc7836a /lib.c | |
parent | 1e399df30ed1e8e1b2c609e90a152d6dab9977e1 (diff) |
lib: extend length() to handle objects
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -368,8 +368,20 @@ static struct json_object * ut_length(struct ut_state *s, uint32_t off, struct json_object *args) { struct json_object *arg = json_object_array_get_idx(args, 0); + size_t len; switch (json_object_get_type(arg)) { + case json_type_object: + len = 0; + + json_object_object_foreach(arg, k, v) { + (void)k; + (void)v; + len++; + } + + return xjs_new_int64(len); + case json_type_array: return xjs_new_int64(json_object_array_length(arg)); |