@@ -213,6 +213,26 @@ void fmt_print_end_group(struct format_ctx *fctx, const char *name)
}
}
+void fmt_print_start_object(struct format_ctx *fctx)
+{
+ if (bconf.output_format == CMD_FORMAT_JSON) {
+ fmt_separator(fctx);
+ fmt_inc_depth(fctx);
+ fctx->memb[fctx->depth] = 0;
+ putchar('{');
+ }
+}
+
+void fmt_print_end_object(struct format_ctx *fctx)
+{
+ if (bconf.output_format == CMD_FORMAT_JSON) {
+ fmt_dec_depth(fctx);
+ putchar('\n');
+ fmt_indent2(fctx->depth);
+ putchar('}');
+ }
+}
+
/* Use rowspec to print according to currently set output format */
void fmt_print(struct format_ctx *fctx, const char* key, ...)
{
@@ -87,4 +87,7 @@ void fmt_print_start_group(struct format_ctx *fctx, const char *name,
enum json_type jtype);
void fmt_print_end_group(struct format_ctx *fctx, const char *name);
+void fmt_print_start_object(struct format_ctx *fctx);
+void fmt_print_end_object(struct format_ctx *fctx);
+
#endif
Introduce a new function that can be used when you need to print an json object in command like "device stats". Signed-off-by: Sidong Yang <realwakka@gmail.com> --- common/format-output.c | 20 ++++++++++++++++++++ common/format-output.h | 3 +++ 2 files changed, 23 insertions(+)