]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - devlink/devlink.c
devlink: Replace pr_#type_value wrapper functions with common functions
[mirror_iproute2.git] / devlink / devlink.c
index ea3f992ee0d74e6ca37ce28fc30cda9de30b229a..231a2838e86f417f2b5fe556c68d12970aa12567 100644 (file)
@@ -395,6 +395,17 @@ static void __pr_out_indent_newline(struct dl *dl)
                pr_out(" ");
 }
 
+static void check_indent_newline(struct dl *dl)
+{
+       __pr_out_indent_newline(dl);
+
+       if (g_indent_newline && !is_json_context()) {
+               printf("%s", g_indent_str);
+               g_indent_newline = false;
+       }
+       g_new_line_count = 0;
+}
+
 static const enum mnl_attr_data_type devlink_policy[DEVLINK_ATTR_MAX + 1] = {
        [DEVLINK_ATTR_BUS_NAME] = MNL_TYPE_NUL_STRING,
        [DEVLINK_ATTR_DEV_NAME] = MNL_TYPE_NUL_STRING,
@@ -1179,6 +1190,7 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required,
                                          &opts->port_index, &handle_bit);
                if (err)
                        return err;
+               o_required &= ~(DL_OPT_HANDLE | DL_OPT_HANDLEP) | handle_bit;
                o_found |= handle_bit;
        } else if (o_required & DL_OPT_HANDLE) {
                err = dl_argv_handle(dl, &opts->bus_name, &opts->dev_name);
@@ -1714,19 +1726,17 @@ static void __pr_out_handle_start(struct dl *dl, struct nlattr **tb,
        if (dl->json_output) {
                if (array) {
                        if (should_arr_last_handle_end(dl, bus_name, dev_name))
-                               jsonw_end_array(dl->jw);
+                               close_json_array(PRINT_JSON, NULL);
                        if (should_arr_last_handle_start(dl, bus_name,
                                                         dev_name)) {
-                               jsonw_name(dl->jw, buf);
-                               jsonw_start_array(dl->jw);
-                               jsonw_start_object(dl->jw);
+                               open_json_array(PRINT_JSON, buf);
+                               open_json_object(NULL);
                                arr_last_handle_set(dl, bus_name, dev_name);
                        } else {
-                               jsonw_start_object(dl->jw);
+                               open_json_object(NULL);
                        }
                } else {
-                       jsonw_name(dl->jw, buf);
-                       jsonw_start_object(dl->jw);
+                       open_json_object(buf);
                }
        } else {
                if (array) {
@@ -1753,7 +1763,7 @@ static void pr_out_handle_start_arr(struct dl *dl, struct nlattr **tb)
 static void pr_out_handle_end(struct dl *dl)
 {
        if (dl->json_output)
-               jsonw_end_object(dl->jw);
+               close_json_object();
        else
                __pr_out_newline();
 }
@@ -1815,21 +1825,19 @@ static void __pr_out_port_handle_start(struct dl *dl, const char *bus_name,
                        if (should_arr_last_port_handle_end(dl, bus_name,
                                                            dev_name,
                                                            port_index))
-                               jsonw_end_array(dl->jw);
+                               close_json_array(PRINT_JSON, NULL);
                        if (should_arr_last_port_handle_start(dl, bus_name,
                                                              dev_name,
                                                              port_index)) {
-                               jsonw_name(dl->jw, buf);
-                               jsonw_start_array(dl->jw);
-                               jsonw_start_object(dl->jw);
+                               open_json_array(PRINT_JSON, buf);
+                               open_json_object(NULL);
                                arr_last_port_handle_set(dl, bus_name, dev_name,
                                                         port_index);
                        } else {
-                               jsonw_start_object(dl->jw);
+                               open_json_object(NULL);
                        }
                } else {
-                       jsonw_name(dl->jw, buf);
-                       jsonw_start_object(dl->jw);
+                       open_json_object(buf);
                }
        } else {
                pr_out("%s:", buf);
@@ -1863,34 +1871,24 @@ static void pr_out_port_handle_start_arr(struct dl *dl, struct nlattr **tb, bool
 static void pr_out_port_handle_end(struct dl *dl)
 {
        if (dl->json_output)
-               jsonw_end_object(dl->jw);
+               close_json_object();
        else
                pr_out("\n");
 }
 
-
-static void pr_out_str(struct dl *dl, const char *name, const char *val)
-{
-       __pr_out_indent_newline(dl);
-       if (dl->json_output)
-               jsonw_string_field(dl->jw, name, val);
-       else
-               pr_out("%s %s", name, val);
-}
-
 static void pr_out_bool(struct dl *dl, const char *name, bool val)
 {
        if (dl->json_output)
-               jsonw_bool_field(dl->jw, name, val);
+               print_bool(PRINT_JSON, name, NULL, val);
        else
-               pr_out_str(dl, name, val ? "true" : "false");
+               print_string_name_value(name, val ? "true" : "false");
 }
 
 static void pr_out_uint(struct dl *dl, const char *name, unsigned int val)
 {
        __pr_out_indent_newline(dl);
        if (dl->json_output)
-               jsonw_uint_field(dl->jw, name, val);
+               print_uint(PRINT_JSON, name, NULL, val);
        else
                pr_out("%s %u", name, val);
 }
@@ -1899,41 +1897,14 @@ static void pr_out_u64(struct dl *dl, const char *name, uint64_t val)
 {
        __pr_out_indent_newline(dl);
        if (val == (uint64_t) -1)
-               return pr_out_str(dl, name, "unlimited");
+               return print_string_name_value(name, "unlimited");
 
        if (dl->json_output)
-               jsonw_u64_field(dl->jw, name, val);
+               print_u64(PRINT_JSON, name, NULL, val);
        else
                pr_out("%s %"PRIu64, name, val);
 }
 
-static void pr_out_bool_value(struct dl *dl, bool value)
-{
-       __pr_out_indent_newline(dl);
-       if (dl->json_output)
-               jsonw_bool(dl->jw, value);
-       else
-               pr_out("%s", value ? "true" : "false");
-}
-
-static void pr_out_uint_value(struct dl *dl, unsigned int value)
-{
-       __pr_out_indent_newline(dl);
-       if (dl->json_output)
-               jsonw_uint(dl->jw, value);
-       else
-               pr_out("%u", value);
-}
-
-static void pr_out_uint64_value(struct dl *dl, uint64_t value)
-{
-       __pr_out_indent_newline(dl);
-       if (dl->json_output)
-               jsonw_u64(dl->jw, value);
-       else
-               pr_out("%"PRIu64, value);
-}
-
 static bool is_binary_eol(int i)
 {
        return !(i%16);
@@ -1945,7 +1916,7 @@ static void pr_out_binary_value(struct dl *dl, uint8_t *data, uint32_t len)
 
        while (i < len) {
                if (dl->json_output)
-                       jsonw_printf(dl->jw, "%d", data[i]);
+                       print_int(PRINT_JSON, NULL, NULL, data[i]);
                else
                        pr_out("%02x ", data[i]);
                i++;
@@ -1956,20 +1927,11 @@ static void pr_out_binary_value(struct dl *dl, uint8_t *data, uint32_t len)
                __pr_out_newline();
 }
 
-static void pr_out_str_value(struct dl *dl, const char *value)
-{
-       __pr_out_indent_newline(dl);
-       if (dl->json_output)
-               jsonw_string(dl->jw, value);
-       else
-               pr_out("%s", value);
-}
-
 static void pr_out_name(struct dl *dl, const char *name)
 {
        __pr_out_indent_newline(dl);
        if (dl->json_output)
-               jsonw_name(dl->jw, name);
+               print_string(PRINT_JSON, name, NULL, NULL);
        else
                pr_out("%s:", name);
 }
@@ -1977,17 +1939,15 @@ static void pr_out_name(struct dl *dl, const char *name)
 static void pr_out_region_chunk_start(struct dl *dl, uint64_t addr)
 {
        if (dl->json_output) {
-               jsonw_name(dl->jw, "address");
-               jsonw_uint(dl->jw, addr);
-               jsonw_name(dl->jw, "data");
-               jsonw_start_array(dl->jw);
+               print_uint(PRINT_JSON, "address", NULL, addr);
+               open_json_array(PRINT_JSON, "data");
        }
 }
 
 static void pr_out_region_chunk_end(struct dl *dl)
 {
        if (dl->json_output)
-               jsonw_end_array(dl->jw);
+               close_json_array(PRINT_JSON, NULL);
 }
 
 static void pr_out_region_chunk(struct dl *dl, uint8_t *data, uint32_t len,
@@ -2007,7 +1967,7 @@ static void pr_out_region_chunk(struct dl *dl, uint8_t *data, uint32_t len,
                align_val++;
 
                if (dl->json_output)
-                       jsonw_printf(dl->jw, "%d", data[i]);
+                       print_int(PRINT_JSON, NULL, NULL, data[i]);
                else
                        pr_out("%02x ", data[i]);
 
@@ -2020,9 +1980,8 @@ static void pr_out_region_chunk(struct dl *dl, uint8_t *data, uint32_t len,
 static void pr_out_section_start(struct dl *dl, const char *name)
 {
        if (dl->json_output) {
-               jsonw_start_object(dl->jw);
-               jsonw_name(dl->jw, name);
-               jsonw_start_object(dl->jw);
+               open_json_object(NULL);
+               open_json_object(name);
        }
 }
 
@@ -2030,17 +1989,16 @@ static void pr_out_section_end(struct dl *dl)
 {
        if (dl->json_output) {
                if (dl->arr_last.present)
-                       jsonw_end_array(dl->jw);
-               jsonw_end_object(dl->jw);
-               jsonw_end_object(dl->jw);
+                       close_json_array(PRINT_JSON, NULL);
+               close_json_object();
+               close_json_object();
        }
 }
 
 static void pr_out_array_start(struct dl *dl, const char *name)
 {
        if (dl->json_output) {
-               jsonw_name(dl->jw, name);
-               jsonw_start_array(dl->jw);
+               open_json_array(PRINT_JSON, name);
        } else {
                __pr_out_indent_inc();
                __pr_out_newline();
@@ -2053,7 +2011,7 @@ static void pr_out_array_start(struct dl *dl, const char *name)
 static void pr_out_array_end(struct dl *dl)
 {
        if (dl->json_output) {
-               jsonw_end_array(dl->jw);
+               close_json_array(PRINT_JSON, NULL);
        } else {
                __pr_out_indent_dec();
                __pr_out_indent_dec();
@@ -2063,8 +2021,7 @@ static void pr_out_array_end(struct dl *dl)
 static void pr_out_object_start(struct dl *dl, const char *name)
 {
        if (dl->json_output) {
-               jsonw_name(dl->jw, name);
-               jsonw_start_object(dl->jw);
+               open_json_object(name);
        } else {
                __pr_out_indent_inc();
                __pr_out_newline();
@@ -2077,7 +2034,7 @@ static void pr_out_object_start(struct dl *dl, const char *name)
 static void pr_out_object_end(struct dl *dl)
 {
        if (dl->json_output) {
-               jsonw_end_object(dl->jw);
+               close_json_object();
        } else {
                __pr_out_indent_dec();
                __pr_out_indent_dec();
@@ -2087,13 +2044,13 @@ static void pr_out_object_end(struct dl *dl)
 static void pr_out_entry_start(struct dl *dl)
 {
        if (dl->json_output)
-               jsonw_start_object(dl->jw);
+               open_json_object(NULL);
 }
 
 static void pr_out_entry_end(struct dl *dl)
 {
        if (dl->json_output)
-               jsonw_end_object(dl->jw);
+               close_json_object();
        else
                __pr_out_newline();
 }
@@ -2164,19 +2121,24 @@ static void pr_out_eswitch(struct dl *dl, struct nlattr **tb)
 {
        __pr_out_handle_start(dl, tb, true, false);
 
-       if (tb[DEVLINK_ATTR_ESWITCH_MODE])
-               pr_out_str(dl, "mode",
-                          eswitch_mode_name(mnl_attr_get_u16(tb[DEVLINK_ATTR_ESWITCH_MODE])));
-
-       if (tb[DEVLINK_ATTR_ESWITCH_INLINE_MODE])
-               pr_out_str(dl, "inline-mode",
-                          eswitch_inline_mode_name(mnl_attr_get_u8(
-                                  tb[DEVLINK_ATTR_ESWITCH_INLINE_MODE])));
-
+       if (tb[DEVLINK_ATTR_ESWITCH_MODE]) {
+               check_indent_newline(dl);
+               print_string(PRINT_ANY, "mode", "mode %s",
+                            eswitch_mode_name(mnl_attr_get_u16(
+                                    tb[DEVLINK_ATTR_ESWITCH_MODE])));
+       }
+       if (tb[DEVLINK_ATTR_ESWITCH_INLINE_MODE]) {
+               check_indent_newline(dl);
+               print_string(PRINT_ANY, "inline-mode", "inline-mode %s",
+                            eswitch_inline_mode_name(mnl_attr_get_u8(
+                                    tb[DEVLINK_ATTR_ESWITCH_INLINE_MODE])));
+       }
        if (tb[DEVLINK_ATTR_ESWITCH_ENCAP_MODE]) {
                bool encap_mode = !!mnl_attr_get_u8(tb[DEVLINK_ATTR_ESWITCH_ENCAP_MODE]);
 
-               pr_out_str(dl, "encap", encap_mode ? "enable" : "disable");
+               check_indent_newline(dl);
+               print_string(PRINT_ANY, "encap", "encap %s",
+                            encap_mode ? "enable" : "disable");
        }
 
        pr_out_handle_end(dl);
@@ -2363,8 +2325,10 @@ static void pr_out_param_value(struct dl *dl, const char *nla_name,
             !nla_value[DEVLINK_ATTR_PARAM_VALUE_DATA]))
                return;
 
-       pr_out_str(dl, "cmode",
-                  param_cmode_name(mnl_attr_get_u8(nla_value[DEVLINK_ATTR_PARAM_VALUE_CMODE])));
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "cmode", "cmode %s",
+                    param_cmode_name(mnl_attr_get_u8(nla_value[DEVLINK_ATTR_PARAM_VALUE_CMODE])));
+
        val_attr = nla_value[DEVLINK_ATTR_PARAM_VALUE_DATA];
 
        conv_exists = param_val_conv_exists(param_val_conv, PARAM_VAL_CONV_LEN,
@@ -2380,7 +2344,7 @@ static void pr_out_param_value(struct dl *dl, const char *nla_name,
                                                     &vstr);
                        if (err)
                                return;
-                       pr_out_str(dl, "value", vstr);
+                       print_string(PRINT_ANY, "value", " value %s", vstr);
                } else {
                        pr_out_uint(dl, "value", mnl_attr_get_u8(val_attr));
                }
@@ -2394,7 +2358,7 @@ static void pr_out_param_value(struct dl *dl, const char *nla_name,
                                                     &vstr);
                        if (err)
                                return;
-                       pr_out_str(dl, "value", vstr);
+                       print_string(PRINT_ANY, "value", " value %s", vstr);
                } else {
                        pr_out_uint(dl, "value", mnl_attr_get_u16(val_attr));
                }
@@ -2408,13 +2372,14 @@ static void pr_out_param_value(struct dl *dl, const char *nla_name,
                                                     &vstr);
                        if (err)
                                return;
-                       pr_out_str(dl, "value", vstr);
+                       print_string(PRINT_ANY, "value", " value %s", vstr);
                } else {
                        pr_out_uint(dl, "value", mnl_attr_get_u32(val_attr));
                }
                break;
        case MNL_TYPE_STRING:
-               pr_out_str(dl, "value", mnl_attr_get_str(val_attr));
+               print_string(PRINT_ANY, "value", " value %s",
+                            mnl_attr_get_str(val_attr));
                break;
        case MNL_TYPE_FLAG:
                pr_out_bool(dl, "value", val_attr ? true : false);
@@ -2446,12 +2411,12 @@ static void pr_out_param(struct dl *dl, struct nlattr **tb, bool array)
        nla_type = mnl_attr_get_u8(nla_param[DEVLINK_ATTR_PARAM_TYPE]);
 
        nla_name = mnl_attr_get_str(nla_param[DEVLINK_ATTR_PARAM_NAME]);
-       pr_out_str(dl, "name", nla_name);
-
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "name", "name %s ", nla_name);
        if (!nla_param[DEVLINK_ATTR_PARAM_GENERIC])
-               pr_out_str(dl, "type", "driver-specific");
+               print_string(PRINT_ANY, "type", "type %s", "driver-specific");
        else
-               pr_out_str(dl, "type", "generic");
+               print_string(PRINT_ANY, "type", "type %s", "generic");
 
        pr_out_array_start(dl, "values");
        mnl_attr_for_each_nested(param_value_attr,
@@ -2815,7 +2780,8 @@ static void pr_out_versions_single(struct dl *dl, const struct nlmsghdr *nlh,
                ver_name = mnl_attr_get_str(tb[DEVLINK_ATTR_INFO_VERSION_NAME]);
                ver_value = mnl_attr_get_str(tb[DEVLINK_ATTR_INFO_VERSION_VALUE]);
 
-               pr_out_str(dl, ver_name, ver_value);
+               check_indent_newline(dl);
+               print_string_name_value(ver_name, ver_value);
                if (!dl->json_output)
                        __pr_out_newline();
        }
@@ -2835,7 +2801,9 @@ static void pr_out_info(struct dl *dl, const struct nlmsghdr *nlh,
 
                if (!dl->json_output)
                        __pr_out_newline();
-               pr_out_str(dl, "driver", mnl_attr_get_str(nla_drv));
+               check_indent_newline(dl);
+               print_string(PRINT_ANY, "driver", "driver %s",
+                            mnl_attr_get_str(nla_drv));
        }
 
        if (tb[DEVLINK_ATTR_INFO_SERIAL_NUMBER]) {
@@ -2843,7 +2811,9 @@ static void pr_out_info(struct dl *dl, const struct nlmsghdr *nlh,
 
                if (!dl->json_output)
                        __pr_out_newline();
-               pr_out_str(dl, "serial_number", mnl_attr_get_str(nla_sn));
+               check_indent_newline(dl);
+               print_string(PRINT_ANY, "serial_number", "serial_number %s",
+                            mnl_attr_get_str(nla_sn));
        }
        __pr_out_indent_dec();
 
@@ -3216,29 +3186,34 @@ static void pr_out_port(struct dl *dl, struct nlattr **tb)
        struct nlattr *dpt_attr = tb[DEVLINK_ATTR_PORT_DESIRED_TYPE];
 
        pr_out_port_handle_start(dl, tb, false);
+       check_indent_newline(dl);
        if (pt_attr) {
                uint16_t port_type = mnl_attr_get_u16(pt_attr);
 
-               pr_out_str(dl, "type", port_type_name(port_type));
+               print_string(PRINT_ANY, "type", "type %s",
+                            port_type_name(port_type));
                if (dpt_attr) {
                        uint16_t des_port_type = mnl_attr_get_u16(dpt_attr);
 
                        if (port_type != des_port_type)
-                               pr_out_str(dl, "des_type",
-                                          port_type_name(des_port_type));
+                               print_string(PRINT_ANY, "des_type", " des_type %s",
+                                            port_type_name(des_port_type));
                }
        }
-       if (tb[DEVLINK_ATTR_PORT_NETDEV_NAME])
-               pr_out_str(dl, "netdev",
-                          mnl_attr_get_str(tb[DEVLINK_ATTR_PORT_NETDEV_NAME]));
-       if (tb[DEVLINK_ATTR_PORT_IBDEV_NAME])
-               pr_out_str(dl, "ibdev",
-                          mnl_attr_get_str(tb[DEVLINK_ATTR_PORT_IBDEV_NAME]));
+       if (tb[DEVLINK_ATTR_PORT_NETDEV_NAME]) {
+               print_string(PRINT_ANY, "netdev", " netdev %s",
+                            mnl_attr_get_str(tb[DEVLINK_ATTR_PORT_NETDEV_NAME]));
+       }
+       if (tb[DEVLINK_ATTR_PORT_IBDEV_NAME]) {
+               print_string(PRINT_ANY, "ibdev", " ibdev %s",
+                            mnl_attr_get_str(tb[DEVLINK_ATTR_PORT_IBDEV_NAME]));
+               }
        if (tb[DEVLINK_ATTR_PORT_FLAVOUR]) {
                uint16_t port_flavour =
                                mnl_attr_get_u16(tb[DEVLINK_ATTR_PORT_FLAVOUR]);
 
-               pr_out_str(dl, "flavour", port_flavour_name(port_flavour));
+               print_string(PRINT_ANY, "flavour", " flavour %s",
+                            port_flavour_name(port_flavour));
 
                switch (port_flavour) {
                case DEVLINK_PORT_FLAVOUR_PCI_PF:
@@ -3389,6 +3364,7 @@ static void cmd_sb_help(void)
 static void pr_out_sb(struct dl *dl, struct nlattr **tb)
 {
        pr_out_handle_start_arr(dl, tb);
+       check_indent_newline(dl);
        pr_out_uint(dl, "sb",
                    mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_INDEX]));
        pr_out_uint(dl, "size",
@@ -3470,12 +3446,12 @@ static void pr_out_sb_pool(struct dl *dl, struct nlattr **tb)
                    mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_INDEX]));
        pr_out_uint(dl, "pool",
                    mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_POOL_INDEX]));
-       pr_out_str(dl, "type",
-                  pool_type_name(mnl_attr_get_u8(tb[DEVLINK_ATTR_SB_POOL_TYPE])));
+       print_string(PRINT_ANY, "type", " type %s",
+                    pool_type_name(mnl_attr_get_u8(tb[DEVLINK_ATTR_SB_POOL_TYPE])));
        pr_out_uint(dl, "size",
                    mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_POOL_SIZE]));
-       pr_out_str(dl, "thtype",
-                  threshold_type_name(mnl_attr_get_u8(tb[DEVLINK_ATTR_SB_POOL_THRESHOLD_TYPE])));
+       print_string(PRINT_ANY, "thtype", " thtype %s",
+                    threshold_type_name(mnl_attr_get_u8(tb[DEVLINK_ATTR_SB_POOL_THRESHOLD_TYPE])));
        if (tb[DEVLINK_ATTR_SB_POOL_CELL_SIZE])
                pr_out_uint(dl, "cell_size",
                            mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_POOL_CELL_SIZE]));
@@ -3660,8 +3636,8 @@ static void pr_out_sb_tc_bind(struct dl *dl, struct nlattr **tb)
               mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_INDEX]));
        pr_out_uint(dl, "tc",
               mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_TC_INDEX]));
-       pr_out_str(dl, "type",
-              pool_type_name(mnl_attr_get_u8(tb[DEVLINK_ATTR_SB_POOL_TYPE])));
+       print_string(PRINT_ANY, "type", " type %s",
+                    pool_type_name(mnl_attr_get_u8(tb[DEVLINK_ATTR_SB_POOL_TYPE])));
        pr_out_uint(dl, "pool",
               mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_POOL_INDEX]));
        pr_out_uint(dl, "threshold",
@@ -3886,20 +3862,18 @@ static void pr_out_json_occ_show_item_list(struct dl *dl, const char *label,
        struct occ_item *occ_item;
        char buf[32];
 
-       jsonw_name(dl->jw, label);
-       jsonw_start_object(dl->jw);
+       open_json_object(label);
        list_for_each_entry(occ_item, list, list) {
                sprintf(buf, "%u", occ_item->index);
-               jsonw_name(dl->jw, buf);
-               jsonw_start_object(dl->jw);
+               open_json_object(buf);
                if (bound_pool)
-                       jsonw_uint_field(dl->jw, "bound_pool",
-                                        occ_item->bound_pool_index);
-               jsonw_uint_field(dl->jw, "current", occ_item->cur);
-               jsonw_uint_field(dl->jw, "max", occ_item->max);
-               jsonw_end_object(dl->jw);
+                       print_uint(PRINT_JSON, "bound_pool", NULL,
+                                  occ_item->bound_pool_index);
+               print_uint(PRINT_JSON, "current", NULL, occ_item->cur);
+               print_uint(PRINT_JSON, "max", NULL, occ_item->max);
+               close_json_object();
        }
-       jsonw_end_object(dl->jw);
+       close_json_object();
 }
 
 static void pr_out_occ_show_port(struct dl *dl, struct occ_port *occ_port)
@@ -4242,13 +4216,16 @@ static void pr_out_flash_update(struct dl *dl, struct nlattr **tb)
 {
        __pr_out_handle_start(dl, tb, true, false);
 
-       if (tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_MSG])
-               pr_out_str(dl, "msg",
-                          mnl_attr_get_str(tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_MSG]));
-
-       if (tb[DEVLINK_ATTR_FLASH_UPDATE_COMPONENT])
-               pr_out_str(dl, "component",
-                          mnl_attr_get_str(tb[DEVLINK_ATTR_FLASH_UPDATE_COMPONENT]));
+       if (tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_MSG]) {
+               check_indent_newline(dl);
+               print_string(PRINT_ANY, "msg", "msg %s",
+                            mnl_attr_get_str(tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_MSG]));
+       }
+       if (tb[DEVLINK_ATTR_FLASH_UPDATE_COMPONENT]) {
+               check_indent_newline(dl);
+               print_string(PRINT_ANY, "component", "component %s",
+                            mnl_attr_get_str(tb[DEVLINK_ATTR_FLASH_UPDATE_COMPONENT]));
+       }
 
        if (tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE])
                pr_out_u64(dl, "done",
@@ -4715,13 +4692,15 @@ static void pr_out_dpipe_fields(struct dpipe_ctx *ctx,
        for (i = 0; i < field_count; i++) {
                field = &fields[i];
                pr_out_entry_start(ctx->dl);
-               pr_out_str(ctx->dl, "name", field->name);
+               check_indent_newline(ctx->dl);
+               print_string(PRINT_ANY, "name", "name %s", field->name);
                if (ctx->dl->verbose)
                        pr_out_uint(ctx->dl, "id", field->id);
                pr_out_uint(ctx->dl, "bitwidth", field->bitwidth);
-               if (field->mapping_type)
-                       pr_out_str(ctx->dl, "mapping_type",
-                                  dpipe_field_mapping_e2s(field->mapping_type));
+               if (field->mapping_type) {
+                       print_string(PRINT_ANY, "mapping_type", " mapping_type %s",
+                                    dpipe_field_mapping_e2s(field->mapping_type));
+               }
                pr_out_entry_end(ctx->dl);
        }
 }
@@ -4731,11 +4710,11 @@ pr_out_dpipe_header(struct dpipe_ctx *ctx, struct nlattr **tb,
                    struct dpipe_header *header, bool global)
 {
        pr_out_handle_start_arr(ctx->dl, tb);
-       pr_out_str(ctx->dl, "name", header->name);
+       check_indent_newline(ctx->dl);
+       print_string(PRINT_ANY, "name", "name %s", header->name);
        if (ctx->dl->verbose) {
                pr_out_uint(ctx->dl, "id", header->id);
-               pr_out_str(ctx->dl, "global",
-                          global ? "true" : "false");
+               print_bool(PRINT_ANY, "global", " global %s", global);
        }
        pr_out_array_start(ctx->dl, "field");
        pr_out_dpipe_fields(ctx, header->fields,
@@ -4959,20 +4938,21 @@ static void pr_out_dpipe_action(struct dpipe_action *action,
        struct dpipe_op_info *op_info = &action->info;
        const char *mapping;
 
-       pr_out_str(ctx->dl, "type",
-                  dpipe_action_type_e2s(action->type));
-       pr_out_str(ctx->dl, "header",
-                  dpipe_header_id2s(ctx, op_info->header_id,
-                                    op_info->header_global));
-       pr_out_str(ctx->dl, "field",
-                  dpipe_field_id2s(ctx, op_info->header_id,
-                                   op_info->field_id,
-                                   op_info->header_global));
+       check_indent_newline(ctx->dl);
+       print_string(PRINT_ANY, "type", "type %s",
+                    dpipe_action_type_e2s(action->type));
+       print_string(PRINT_ANY, "header", " header %s",
+                    dpipe_header_id2s(ctx, op_info->header_id,
+                                      op_info->header_global));
+       print_string(PRINT_ANY, "field", " field %s",
+                    dpipe_field_id2s(ctx, op_info->header_id,
+                                     op_info->field_id,
+                                     op_info->header_global));
        mapping = dpipe_mapping_get(ctx, op_info->header_id,
                                    op_info->field_id,
                                    op_info->header_global);
        if (mapping)
-               pr_out_str(ctx->dl, "mapping", mapping);
+               print_string(PRINT_ANY, "mapping", " mapping %s", mapping);
 }
 
 static int dpipe_action_parse(struct dpipe_action *action, struct nlattr *nl)
@@ -5041,20 +5021,21 @@ static void pr_out_dpipe_match(struct dpipe_match *match,
        struct dpipe_op_info *op_info = &match->info;
        const char *mapping;
 
-       pr_out_str(ctx->dl, "type",
-                  dpipe_match_type_e2s(match->type));
-       pr_out_str(ctx->dl, "header",
-                  dpipe_header_id2s(ctx, op_info->header_id,
-                                    op_info->header_global));
-       pr_out_str(ctx->dl, "field",
-                  dpipe_field_id2s(ctx, op_info->header_id,
-                                   op_info->field_id,
-                                   op_info->header_global));
+       check_indent_newline(ctx->dl);
+       print_string(PRINT_ANY, "type", "type %s",
+                    dpipe_match_type_e2s(match->type));
+       print_string(PRINT_ANY, "header", " header %s",
+                    dpipe_header_id2s(ctx, op_info->header_id,
+                                      op_info->header_global));
+       print_string(PRINT_ANY, "field", " field %s",
+                    dpipe_field_id2s(ctx, op_info->header_id,
+                                     op_info->field_id,
+                                     op_info->header_global));
        mapping = dpipe_mapping_get(ctx, op_info->header_id,
                                    op_info->field_id,
                                    op_info->header_global);
        if (mapping)
-               pr_out_str(ctx->dl, "mapping", mapping);
+               print_string(PRINT_ANY, "mapping", " mapping %s", mapping);
 }
 
 static int dpipe_match_parse(struct dpipe_match *match,
@@ -5159,7 +5140,8 @@ resource_path_print(struct dl *dl, struct resources *resources,
                path -= strlen(del);
                memcpy(path, del, strlen(del));
        }
-       pr_out_str(dl, "resource_path", path);
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "resource_path", "resource_path %s", path);
        free(path);
 }
 
@@ -5204,10 +5186,10 @@ static int dpipe_table_show(struct dpipe_ctx *ctx, struct nlattr *nl)
        if (!ctx->print_tables)
                return 0;
 
-       pr_out_str(ctx->dl, "name", table->name);
+       check_indent_newline(ctx->dl);
+       print_string(PRINT_ANY, "name", "name %s", table->name);
        pr_out_uint(ctx->dl, "size", size);
-       pr_out_str(ctx->dl, "counters_enabled",
-                  counters_enabled ? "true" : "false");
+       print_bool(PRINT_ANY, "counters_enabled", " counters_enabled %s", counters_enabled);
 
        if (resource_valid) {
                resource_units = mnl_attr_get_u32(nla_table[DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_UNITS]);
@@ -5384,7 +5366,8 @@ static void dpipe_field_printer_ipv4_addr(struct dpipe_ctx *ctx,
        struct in_addr ip_addr;
 
        ip_addr.s_addr = htonl(*(uint32_t *)value);
-       pr_out_str(ctx->dl, dpipe_value_type_e2s(type), inet_ntoa(ip_addr));
+       check_indent_newline(ctx->dl);
+       print_string_name_value(dpipe_value_type_e2s(type), inet_ntoa(ip_addr));
 }
 
 static void
@@ -5392,8 +5375,9 @@ dpipe_field_printer_ethernet_addr(struct dpipe_ctx *ctx,
                                  enum dpipe_value_type type,
                                  void *value)
 {
-       pr_out_str(ctx->dl, dpipe_value_type_e2s(type),
-                  ether_ntoa((struct ether_addr *)value));
+       check_indent_newline(ctx->dl);
+       print_string_name_value(dpipe_value_type_e2s(type),
+                               ether_ntoa((struct ether_addr *)value));
 }
 
 static void dpipe_field_printer_ipv6_addr(struct dpipe_ctx *ctx,
@@ -5403,7 +5387,8 @@ static void dpipe_field_printer_ipv6_addr(struct dpipe_ctx *ctx,
        char str[INET6_ADDRSTRLEN];
 
        inet_ntop(AF_INET6, value, str, INET6_ADDRSTRLEN);
-       pr_out_str(ctx->dl, dpipe_value_type_e2s(type), str);
+       check_indent_newline(ctx->dl);
+       print_string_name_value(dpipe_value_type_e2s(type), str);
 }
 
 static struct dpipe_field_printer dpipe_field_printers_ipv4[] = {
@@ -5882,7 +5867,8 @@ static void resource_show(struct resource *resource,
        struct dl *dl = ctx->dl;
        bool array = false;
 
-       pr_out_str(dl, "name", resource->name);
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "name", "name %s", resource->name);
        if (dl->verbose)
                resource_path_print(dl, ctx->resources, resource->id);
        pr_out_u64(dl, "size", resource->size);
@@ -5890,7 +5876,8 @@ static void resource_show(struct resource *resource,
                pr_out_u64(dl, "size_new", resource->size_new);
        if (resource->occ_valid)
                pr_out_uint(dl, "occ", resource->size_occ);
-       pr_out_str(dl, "unit", resource_unit_str_get(resource->unit));
+       print_string(PRINT_ANY, "unit", " unit %s",
+                    resource_unit_str_get(resource->unit));
 
        if (resource->size_min != resource->size_max) {
                pr_out_uint(dl, "size_min", resource->size_min);
@@ -5906,14 +5893,17 @@ static void resource_show(struct resource *resource,
        if (array)
                pr_out_array_start(dl, "dpipe_tables");
        else
-               pr_out_str(dl, "dpipe_tables", "none");
+               print_string(PRINT_ANY, "dpipe_tables", " dpipe_tables none",
+                            "none");
 
        list_for_each_entry(table, &ctx->tables->table_list, list) {
                if (table->resource_id != resource->id ||
                    !table->resource_valid)
                        continue;
                pr_out_entry_start(dl);
-               pr_out_str(dl, "table_name", table->name);
+               check_indent_newline(dl);
+               print_string(PRINT_ANY, "table_name", "table_name %s",
+                            table->name);
                pr_out_entry_end(dl);
        }
        if (array)
@@ -5922,9 +5912,11 @@ static void resource_show(struct resource *resource,
        if (list_empty(&resource->resource_list))
                return;
 
-       if (ctx->pending_change)
-               pr_out_str(dl, "size_valid", resource->size_valid ?
-                          "true" : "false");
+       if (ctx->pending_change) {
+               check_indent_newline(dl);
+               print_string(PRINT_ANY, "size_valid", "size_valid %s",
+                            resource->size_valid ? "true" : "false");
+       }
        pr_out_array_start(dl, "resources");
        list_for_each_entry(child_resource, &resource->resource_list, list) {
                pr_out_entry_start(dl);
@@ -6139,18 +6131,16 @@ static void pr_out_region_handle_start(struct dl *dl, struct nlattr **tb)
        char buf[256];
 
        sprintf(buf, "%s/%s/%s", bus_name, dev_name, region_name);
-       if (dl->json_output) {
-               jsonw_name(dl->jw, buf);
-               jsonw_start_object(dl->jw);
-       } else {
+       if (dl->json_output)
+               open_json_object(buf);
+       else
                pr_out("%s:", buf);
-       }
 }
 
 static void pr_out_region_handle_end(struct dl *dl)
 {
        if (dl->json_output)
-               jsonw_end_object(dl->jw);
+               close_json_object();
        else
                pr_out("\n");
 }
@@ -6158,18 +6148,16 @@ static void pr_out_region_handle_end(struct dl *dl)
 static void pr_out_region_snapshots_start(struct dl *dl, bool array)
 {
        __pr_out_indent_newline(dl);
-       if (dl->json_output) {
-               jsonw_name(dl->jw, "snapshot");
-               jsonw_start_array(dl->jw);
-       } else {
+       if (dl->json_output)
+               open_json_array(PRINT_JSON, "snapshot");
+       else
                pr_out("snapshot %s", array ? "[" : "");
-       }
 }
 
 static void pr_out_region_snapshots_end(struct dl *dl, bool array)
 {
        if (dl->json_output)
-               jsonw_end_array(dl->jw);
+               close_json_array(PRINT_JSON, NULL);
        else if (array)
                pr_out("]");
 }
@@ -6184,7 +6172,7 @@ static void pr_out_region_snapshots_id(struct dl *dl, struct nlattr **tb, int in
        snapshot_id = mnl_attr_get_u32(tb[DEVLINK_ATTR_REGION_SNAPSHOT_ID]);
 
        if (dl->json_output)
-               jsonw_uint(dl->jw, snapshot_id);
+               print_uint(PRINT_JSON, NULL, NULL, snapshot_id);
        else
                pr_out("%s%u", index ? " " : "", snapshot_id);
 }
@@ -6432,24 +6420,25 @@ static int fmsg_value_show(struct dl *dl, int type, struct nlattr *nl_data)
        uint8_t *data;
        uint32_t len;
 
+       check_indent_newline(dl);
        switch (type) {
        case MNL_TYPE_FLAG:
-               pr_out_bool_value(dl, mnl_attr_get_u8(nl_data));
+               print_bool(PRINT_ANY, NULL, "%s", mnl_attr_get_u8(nl_data));
                break;
        case MNL_TYPE_U8:
-               pr_out_uint_value(dl, mnl_attr_get_u8(nl_data));
+               print_uint(PRINT_ANY, NULL, "%u", mnl_attr_get_u8(nl_data));
                break;
        case MNL_TYPE_U16:
-               pr_out_uint_value(dl, mnl_attr_get_u16(nl_data));
+               print_uint(PRINT_ANY, NULL, "%u", mnl_attr_get_u16(nl_data));
                break;
        case MNL_TYPE_U32:
-               pr_out_uint_value(dl, mnl_attr_get_u32(nl_data));
+               print_uint(PRINT_ANY, NULL, "%u", mnl_attr_get_u32(nl_data));
                break;
        case MNL_TYPE_U64:
-               pr_out_uint64_value(dl, mnl_attr_get_u64(nl_data));
+               print_u64(PRINT_ANY, NULL, "%"PRIu64, mnl_attr_get_u64(nl_data));
                break;
        case MNL_TYPE_NUL_STRING:
-               pr_out_str_value(dl, mnl_attr_get_str(nl_data));
+               print_string(PRINT_ANY, NULL, "%s", mnl_attr_get_str(nl_data));
                break;
        case MNL_TYPE_BINARY:
                len = mnl_attr_get_payload_len(nl_data);
@@ -6462,12 +6451,23 @@ static int fmsg_value_show(struct dl *dl, int type, struct nlattr *nl_data)
        return MNL_CB_OK;
 }
 
+static void pr_out_fmsg_name(struct dl *dl, char **name)
+{
+       if (!*name)
+               return;
+
+       pr_out_name(dl, *name);
+       free(*name);
+       *name = NULL;
+}
+
 struct nest_entry {
        int attr_type;
        struct list_head list;
 };
 
 struct fmsg_cb_data {
+       char *name;
        struct dl *dl;
        uint8_t value_type;
        struct list_head entry_list;
@@ -6497,6 +6497,56 @@ static int cmd_fmsg_nest_queue(struct fmsg_cb_data *fmsg_data,
        return MNL_CB_OK;
 }
 
+static void pr_out_fmsg_group_start(struct dl *dl, char **name)
+{
+       __pr_out_newline();
+       pr_out_fmsg_name(dl, name);
+       __pr_out_newline();
+       __pr_out_indent_inc();
+}
+
+static void pr_out_fmsg_group_end(struct dl *dl)
+{
+       __pr_out_newline();
+       __pr_out_indent_dec();
+}
+
+static void pr_out_fmsg_start_object(struct dl *dl, char **name)
+{
+       if (dl->json_output) {
+               pr_out_fmsg_name(dl, name);
+               open_json_object(NULL);
+       } else {
+               pr_out_fmsg_group_start(dl, name);
+       }
+}
+
+static void pr_out_fmsg_end_object(struct dl *dl)
+{
+       if (dl->json_output)
+               close_json_object();
+       else
+               pr_out_fmsg_group_end(dl);
+}
+
+static void pr_out_fmsg_start_array(struct dl *dl, char **name)
+{
+       if (dl->json_output) {
+               pr_out_fmsg_name(dl, name);
+               open_json_array(PRINT_JSON, NULL);
+       } else {
+               pr_out_fmsg_group_start(dl, name);
+       }
+}
+
+static void pr_out_fmsg_end_array(struct dl *dl)
+{
+       if (dl->json_output)
+               close_json_array(PRINT_JSON, NULL);
+       else
+               pr_out_fmsg_group_end(dl);
+}
+
 static int cmd_fmsg_nest(struct fmsg_cb_data *fmsg_data, uint8_t nest_value,
                         bool start)
 {
@@ -6511,26 +6561,17 @@ static int cmd_fmsg_nest(struct fmsg_cb_data *fmsg_data, uint8_t nest_value,
        switch (value) {
        case DEVLINK_ATTR_FMSG_OBJ_NEST_START:
                if (start)
-                       pr_out_entry_start(dl);
+                       pr_out_fmsg_start_object(dl, &fmsg_data->name);
                else
-                       pr_out_entry_end(dl);
+                       pr_out_fmsg_end_object(dl);
                break;
        case DEVLINK_ATTR_FMSG_PAIR_NEST_START:
                break;
        case DEVLINK_ATTR_FMSG_ARR_NEST_START:
-               if (dl->json_output) {
-                       if (start)
-                               jsonw_start_array(dl->jw);
-                       else
-                               jsonw_end_array(dl->jw);
-               } else {
-                       if (start) {
-                               __pr_out_newline();
-                               __pr_out_indent_inc();
-                       } else {
-                               __pr_out_indent_dec();
-                       }
-               }
+               if (start)
+                       pr_out_fmsg_start_array(dl, &fmsg_data->name);
+               else
+                       pr_out_fmsg_end_array(dl);
                break;
        default:
                return -EINVAL;
@@ -6568,12 +6609,16 @@ static int cmd_fmsg_object_cb(const struct nlmsghdr *nlh, void *data)
                                return err;
                        break;
                case DEVLINK_ATTR_FMSG_OBJ_NAME:
-                       pr_out_name(dl, mnl_attr_get_str(nla_object));
+                       free(fmsg_data->name);
+                       fmsg_data->name = strdup(mnl_attr_get_str(nla_object));
+                       if (!fmsg_data->name)
+                               return -ENOMEM;
                        break;
                case DEVLINK_ATTR_FMSG_OBJ_VALUE_TYPE:
                        fmsg_data->value_type = mnl_attr_get_u8(nla_object);
                        break;
                case DEVLINK_ATTR_FMSG_OBJ_VALUE_DATA:
+                       pr_out_fmsg_name(dl, &fmsg_data->name);
                        err = fmsg_value_show(dl, fmsg_data->value_type,
                                              nla_object);
                        if (err != MNL_CB_OK)
@@ -6586,6 +6631,20 @@ static int cmd_fmsg_object_cb(const struct nlmsghdr *nlh, void *data)
        return MNL_CB_OK;
 }
 
+static void cmd_fmsg_init(struct dl *dl, struct fmsg_cb_data *data)
+{
+       /* FMSG is dynamic: opening of an object or array causes a
+        * newline. JSON starts with an { or [, but plain text should
+        * not start with a new line. Ensure this by setting
+        * g_new_line_count to 1: avoiding newline before the first
+        * print.
+        */
+       g_new_line_count = 1;
+       data->name = NULL;
+       data->dl = dl;
+       INIT_LIST_HEAD(&data->entry_list);
+}
+
 static int cmd_health_object_common(struct dl *dl, uint8_t cmd, uint16_t flags)
 {
        struct fmsg_cb_data data;
@@ -6599,9 +6658,9 @@ static int cmd_health_object_common(struct dl *dl, uint8_t cmd, uint16_t flags)
        if (err)
                return err;
 
-       data.dl = dl;
-       INIT_LIST_HEAD(&data.entry_list);
+       cmd_fmsg_init(dl, &data);
        err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_fmsg_object_cb, &data);
+       free(data.name);
        return err;
 }
 
@@ -6653,8 +6712,11 @@ static const char *health_state_name(uint8_t state)
        }
 }
 
-static void format_logtime(uint64_t time_ms, char *ts_date, char *ts_time)
+static void pr_out_dump_reporter_format_logtime(struct dl *dl, const struct nlattr *attr)
 {
+       char dump_date[HEALTH_REPORTER_TIMESTAMP_FMT_LEN];
+       char dump_time[HEALTH_REPORTER_TIMESTAMP_FMT_LEN];
+       uint64_t time_ms = mnl_attr_get_u64(attr);
        struct sysinfo s_info;
        struct tm *info;
        time_t now, sec;
@@ -6672,16 +6734,37 @@ static void format_logtime(uint64_t time_ms, char *ts_date, char *ts_time)
        sec = now - s_info.uptime + time_ms / 1000;
        info = localtime(&sec);
 out:
-       strftime(ts_date, HEALTH_REPORTER_TIMESTAMP_FMT_LEN, "%Y-%m-%d", info);
-       strftime(ts_time, HEALTH_REPORTER_TIMESTAMP_FMT_LEN, "%H:%M:%S", info);
+       strftime(dump_date, HEALTH_REPORTER_TIMESTAMP_FMT_LEN, "%Y-%m-%d", info);
+       strftime(dump_time, HEALTH_REPORTER_TIMESTAMP_FMT_LEN, "%H:%M:%S", info);
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "last_dump_date", "last_dump_date %s", dump_date);
+       print_string(PRINT_ANY, "last_dump_time", " last_dump_time %s", dump_time);
+}
+
+static void pr_out_dump_report_timestamp(struct dl *dl, const struct nlattr *attr)
+{
+       char dump_date[HEALTH_REPORTER_TIMESTAMP_FMT_LEN];
+       char dump_time[HEALTH_REPORTER_TIMESTAMP_FMT_LEN];
+       time_t tv_sec;
+       struct tm *tm;
+       uint64_t ts;
+
+       ts = mnl_attr_get_u64(attr);
+       tv_sec = ts / 1000000000;
+       tm = localtime(&tv_sec);
+
+       strftime(dump_date, HEALTH_REPORTER_TIMESTAMP_FMT_LEN, "%Y-%m-%d", tm);
+       strftime(dump_time, HEALTH_REPORTER_TIMESTAMP_FMT_LEN, "%H:%M:%S", tm);
+
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "last_dump_date", "last_dump_date %s", dump_date);
+       print_string(PRINT_ANY, "last_dump_time", " last_dump_time %s", dump_time);
 }
 
 static void pr_out_health(struct dl *dl, struct nlattr **tb_health)
 {
        struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
        enum devlink_health_reporter_state state;
-       const struct nlattr *attr;
-       uint64_t time_ms;
        int err;
 
        err = mnl_attr_parse_nested(tb_health[DEVLINK_ATTR_HEALTH_REPORTER],
@@ -6697,29 +6780,24 @@ static void pr_out_health(struct dl *dl, struct nlattr **tb_health)
 
        pr_out_handle_start_arr(dl, tb_health);
 
-       pr_out_str(dl, "reporter",
-                  mnl_attr_get_str(tb[DEVLINK_ATTR_HEALTH_REPORTER_NAME]));
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "reporter", "reporter %s",
+                    mnl_attr_get_str(tb[DEVLINK_ATTR_HEALTH_REPORTER_NAME]));
        if (!dl->json_output) {
                __pr_out_newline();
                __pr_out_indent_inc();
        }
        state = mnl_attr_get_u8(tb[DEVLINK_ATTR_HEALTH_REPORTER_STATE]);
-       pr_out_str(dl, "state", health_state_name(state));
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "state", "state %s", health_state_name(state));
        pr_out_u64(dl, "error",
                   mnl_attr_get_u64(tb[DEVLINK_ATTR_HEALTH_REPORTER_ERR_COUNT]));
        pr_out_u64(dl, "recover",
                   mnl_attr_get_u64(tb[DEVLINK_ATTR_HEALTH_REPORTER_RECOVER_COUNT]));
-       if (tb[DEVLINK_ATTR_HEALTH_REPORTER_DUMP_TS]) {
-               char dump_date[HEALTH_REPORTER_TIMESTAMP_FMT_LEN];
-               char dump_time[HEALTH_REPORTER_TIMESTAMP_FMT_LEN];
-
-               attr = tb[DEVLINK_ATTR_HEALTH_REPORTER_DUMP_TS];
-               time_ms = mnl_attr_get_u64(attr);
-               format_logtime(time_ms, dump_date, dump_time);
-
-               pr_out_str(dl, "last_dump_date", dump_date);
-               pr_out_str(dl, "last_dump_time", dump_time);
-       }
+       if (tb[DEVLINK_ATTR_HEALTH_REPORTER_DUMP_TS_NS])
+               pr_out_dump_report_timestamp(dl, tb[DEVLINK_ATTR_HEALTH_REPORTER_DUMP_TS_NS]);
+       else if (tb[DEVLINK_ATTR_HEALTH_REPORTER_DUMP_TS])
+               pr_out_dump_reporter_format_logtime(dl, tb[DEVLINK_ATTR_HEALTH_REPORTER_DUMP_TS]);
        if (tb[DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD])
                pr_out_u64(dl, "grace_period",
                           mnl_attr_get_u64(tb[DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD]));
@@ -6852,8 +6930,11 @@ static void pr_out_trap_metadata(struct dl *dl, struct nlattr *attr)
        struct nlattr *attr_metadata;
 
        pr_out_array_start(dl, "metadata");
-       mnl_attr_for_each_nested(attr_metadata, attr)
-               pr_out_str_value(dl, trap_metadata_name(attr_metadata));
+       mnl_attr_for_each_nested(attr_metadata, attr) {
+               check_indent_newline(dl);
+               print_string(PRINT_ANY, NULL, "%s",
+                            trap_metadata_name(attr_metadata));
+       }
        pr_out_array_end(dl);
 }
 
@@ -6867,12 +6948,14 @@ static void pr_out_trap(struct dl *dl, struct nlattr **tb, bool array)
        else
                __pr_out_handle_start(dl, tb, true, false);
 
-       pr_out_str(dl, "name", mnl_attr_get_str(tb[DEVLINK_ATTR_TRAP_NAME]));
-       pr_out_str(dl, "type", trap_type_name(type));
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "name", "name %s",
+                    mnl_attr_get_str(tb[DEVLINK_ATTR_TRAP_NAME]));
+       print_string(PRINT_ANY, "type", " type %s", trap_type_name(type));
        pr_out_bool(dl, "generic", !!tb[DEVLINK_ATTR_TRAP_GENERIC]);
-       pr_out_str(dl, "action", trap_action_name(action));
-       pr_out_str(dl, "group",
-                  mnl_attr_get_str(tb[DEVLINK_ATTR_TRAP_GROUP_NAME]));
+       print_string(PRINT_ANY, "action", " action %s", trap_action_name(action));
+       print_string(PRINT_ANY, "group", " group %s",
+                    mnl_attr_get_str(tb[DEVLINK_ATTR_TRAP_GROUP_NAME]));
        if (dl->verbose)
                pr_out_trap_metadata(dl, tb[DEVLINK_ATTR_TRAP_METADATA]);
        pr_out_stats(dl, tb[DEVLINK_ATTR_STATS]);
@@ -6954,8 +7037,9 @@ static void pr_out_trap_group(struct dl *dl, struct nlattr **tb, bool array)
        else
                __pr_out_handle_start(dl, tb, true, false);
 
-       pr_out_str(dl, "name",
-                  mnl_attr_get_str(tb[DEVLINK_ATTR_TRAP_GROUP_NAME]));
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "name", "name %s",
+                    mnl_attr_get_str(tb[DEVLINK_ATTR_TRAP_GROUP_NAME]));
        pr_out_bool(dl, "generic", !!tb[DEVLINK_ATTR_TRAP_GENERIC]);
        pr_out_stats(dl, tb[DEVLINK_ATTR_STATS]);
        pr_out_handle_end(dl);
@@ -7120,18 +7204,9 @@ static int dl_init(struct dl *dl)
                pr_err("Failed to create index map\n");
                goto err_ifname_map_create;
        }
-       if (dl->json_output) {
-               dl->jw = jsonw_new(stdout);
-               if (!dl->jw) {
-                       pr_err("Failed to create JSON writer\n");
-                       goto err_json_new;
-               }
-               jsonw_pretty(dl->jw, dl->pretty_output);
-       }
+       new_json_obj_plain(dl->json_output);
        return 0;
 
-err_json_new:
-       ifname_map_fini(dl);
 err_ifname_map_create:
        mnlg_socket_close(dl->nlg);
        return err;
@@ -7139,8 +7214,7 @@ err_ifname_map_create:
 
 static void dl_fini(struct dl *dl)
 {
-       if (dl->json_output)
-               jsonw_destroy(&dl->jw);
+       delete_json_obj_plain();
        ifname_map_fini(dl);
        mnlg_socket_close(dl->nlg);
 }
@@ -7247,7 +7321,7 @@ int main(int argc, char **argv)
                        dl->json_output = true;
                        break;
                case 'p':
-                       dl->pretty_output = true;
+                       pretty = true;
                        break;
                case 'v':
                        dl->verbose = true;