summaryrefslogtreecommitdiffstats
path: root/lib/json.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/json.h')
-rw-r--r--lib/json.h14
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>