diff options
author | Rafael Zalamena <rzalamena@opensourcerouting.org> | 2018-05-22 15:48:18 +0200 |
---|---|---|
committer | Rafael Zalamena <rzalamena@opensourcerouting.org> | 2018-08-08 23:01:20 +0200 |
commit | 8519fe88c9fc6a3e217148fd2edd8d815269ec8a (patch) | |
tree | 695b271bffeacbc56e27d00a15d60f6b6c8c5fed /lib/json.h | |
parent | Merge pull request #2790 from lyq140/branch1 (diff) | |
download | frr-8519fe88c9fc6a3e217148fd2edd8d815269ec8a.tar.xz frr-8519fe88c9fc6a3e217148fd2edd8d815269ec8a.zip |
lib: import new JSON iteration macro
Save a few lines when iterating over JSON objects using the new
JSON_FOREACH macro.
Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
Diffstat (limited to 'lib/json.h')
-rw-r--r-- | lib/json.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/json.h b/lib/json.h index 675d852af..788d1d6ef 100644 --- a/lib/json.h +++ b/lib/json.h @@ -23,6 +23,20 @@ #if defined(HAVE_JSON_C_JSON_H) #include <json-c/json.h> + +/* + * FRR style JSON iteration. + * Usage: JSON_FOREACH(...) { ... } + */ +#define JSON_FOREACH(jo, joi, join) \ + /* struct json_object *jo; */ \ + /* struct json_object_iterator joi; */ \ + /* struct json_object_iterator join; */ \ + for ((joi) = json_object_iter_begin((jo)), \ + (join) = json_object_iter_end((jo)); \ + json_object_iter_equal(&(joi), &(join)) == 0; \ + json_object_iter_next(&(joi))) + #else #include <json/json.h> |