summaryrefslogtreecommitdiff
path: root/lib/vty.c
diff options
context:
space:
mode:
authorLouis Scalbert <louis.scalbert@6wind.com>2024-05-27 10:04:14 +0200
committerLouis Scalbert <louis.scalbert@6wind.com>2024-06-07 10:13:26 +0200
commit03b1ee7a39d1ac166f4dff62c75374f85029c918 (patch)
tree0eeb215a4096038e6cecfba24022a937f42e80da /lib/vty.c
parent0c6f14ec145342ce793db8ae4efa31adc2972e21 (diff)
lib: add helpers to print json keys
Add helpers to print json keys in order to prepare the next commits. Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
Diffstat (limited to 'lib/vty.c')
-rw-r--r--lib/vty.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/vty.c b/lib/vty.c
index 628c694e95..0dcd118a97 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -390,6 +390,21 @@ int vty_json_no_pretty(struct vty *vty, struct json_object *json)
return vty_json_helper(vty, json, JSON_C_TO_STRING_NOSLASHESCAPE);
}
+
+void vty_json_key(struct vty *vty, const char *key, bool *first_key)
+{
+ vty_out(vty, "%s\"%s\":", *first_key ? "{" : ",", key);
+ *first_key = false;
+}
+
+void vty_json_close(struct vty *vty, bool first_key)
+{
+ if (first_key)
+ /* JSON was not opened */
+ vty_out(vty, "{");
+ vty_out(vty, "}\n");
+}
+
void vty_json_empty(struct vty *vty, struct json_object *json)
{
json_object *jsonobj = json;