summaryrefslogtreecommitdiffstats
path: root/lib/vty.c
diff options
context:
space:
mode:
authorDonatas Abraitis <donatas.abraitis@gmail.com>2021-11-18 09:33:52 +0100
committerGitHub <noreply@github.com>2021-11-18 09:33:52 +0100
commitd86cf7aa6584265419733b6c7419b9864df08dc2 (patch)
tree87d931e6b55067d788bbe3687bfab7352fcdeb6e /lib/vty.c
parentMerge pull request #10089 from donaldsharp/really_remove (diff)
parentlib: use json-printf in filter code (diff)
downloadfrr-d86cf7aa6584265419733b6c7419b9864df08dc2.tar.xz
frr-d86cf7aa6584265419733b6c7419b9864df08dc2.zip
Merge pull request #10084 from opensourcerouting/json-sugar
lib: make JSON output less painful/boilerplate-y
Diffstat (limited to 'lib/vty.c')
-rw-r--r--lib/vty.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/vty.c b/lib/vty.c
index 3df623502..8eaf13619 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -48,6 +48,7 @@
#include "lib_errors.h"
#include "northbound_cli.h"
#include "printfrr.h"
+#include "json.h"
#include <arpa/telnet.h>
#include <termios.h>
@@ -280,6 +281,21 @@ done:
return len;
}
+int vty_json(struct vty *vty, struct json_object *json)
+{
+ const char *text;
+
+ if (!json)
+ return CMD_SUCCESS;
+
+ text = json_object_to_json_string_ext(
+ json, JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_NOSLASHESCAPE);
+ vty_out(vty, "%s\n", text);
+ json_object_free(json);
+
+ return CMD_SUCCESS;
+}
+
/* Output current time to the vty. */
void vty_time_print(struct vty *vty, int cr)
{