]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
lnstat: convert to high-level json_print API
authorAndrea Claudi <aclaudi@redhat.com>
Tue, 21 Oct 2025 20:39:18 +0000 (22:39 +0200)
committerDavid Ahern <dsahern@kernel.org>
Sun, 26 Oct 2025 23:14:14 +0000 (17:14 -0600)
Replace the low-level json_writer API calls with the high-level
json_print API to maintain consistency with the rest of the iproute2
codebase.

Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
misc/lnstat.c

index f802a0f354da99b14ad600e1e7bb222107549886..8f359578c8484507c18c0f828269d7616d4b7b91 100644 (file)
@@ -30,8 +30,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <getopt.h>
+#include <linux/types.h>
 
-#include <json_writer.h>
+#include "json_print.h"
 #include "lnstat.h"
 #include "version.h"
 
@@ -109,21 +110,17 @@ static void print_line(FILE *of, const struct lnstat_file *lnstat_files,
 static void print_json(FILE *of, const struct lnstat_file *lnstat_files,
                       const struct field_params *fp)
 {
-       json_writer_t *jw = jsonw_new(of);
        int i;
 
-       if (jw == NULL) {
-               fprintf(stderr, "Failed to create JSON writer\n");
-               exit(1);
-       }
-       jsonw_start_object(jw);
+       new_json_obj_plain(1);
+       open_json_object(NULL);
        for (i = 0; i < fp->num; i++) {
                const struct lnstat_field *lf = fp->params[i].lf;
 
-               jsonw_uint_field(jw, lf->name, lf->result);
+               print_luint(PRINT_JSON, lf->name, NULL, lf->result);
        }
-       jsonw_end_object(jw);
-       jsonw_destroy(&jw);
+       close_json_object();
+       delete_json_obj_plain();
 }
 
 /* find lnstat_field according to user specification */