diff options
author | Donatas Abraitis <donatas.abraitis@gmail.com> | 2021-11-18 09:33:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-18 09:33:52 +0100 |
commit | d86cf7aa6584265419733b6c7419b9864df08dc2 (patch) | |
tree | 87d931e6b55067d788bbe3687bfab7352fcdeb6e /lib/vty.c | |
parent | Merge pull request #10089 from donaldsharp/really_remove (diff) | |
parent | lib: use json-printf in filter code (diff) | |
download | frr-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.c | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -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) { |