From 6e53be736e75e3c270432ed07234e9884d135ed1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B6ppner?= Date: Wed, 1 Apr 2026 18:27:37 +0200 Subject: [PATCH] chpstat: Adapt to new JSON Lines text format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit util_fmt now provides support for JSON Lines text format. Adapt certain checks in the code and document the newly supported format in the man page accordingly. Reviewed-by: Peter Oberparleiter Signed-off-by: Jan Höppner --- zconf/chp/chpstat/chpstat.8 | 17 +++++++++++++++++ zconf/chp/chpstat/chpstat.c | 6 +++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/zconf/chp/chpstat/chpstat.8 b/zconf/chp/chpstat/chpstat.8 index f2e6542f..3d15e39d 100644 --- a/zconf/chp/chpstat/chpstat.8 +++ b/zconf/chp/chpstat/chpstat.8 @@ -384,6 +384,17 @@ with an ASCII Record Separator character (0x1e) and suffixed with an ASCII Line Feed character (0x0a) in accordance with RFC7464. .br +See section "OUTPUT FORMAT" for more details. +.BR +.PP +.IP \(bu 3 +.B jsonl: +Line-delimited JSON data structures + +Data for each iteration is formatted as a single JSON data structure separated +by an ASCII Line Feed character (0x0a, LF). +.BR + See section "OUTPUT FORMAT" for more details. .br .PP @@ -736,6 +747,12 @@ Subsequent objects each represent channel-path statistics data for one iteration .br .PP +.SS jsonl + +The jsonl output format is a data streaming variation of the JSON output format +described above with the same properties as the json\-seq output with the +difference that JSON data is separated only by an ASCII Line Feed character +(0x0a, LF). .SH "EXIT CODES" .TP diff --git a/zconf/chp/chpstat/chpstat.c b/zconf/chp/chpstat/chpstat.c index 699aa132..8e08c069 100644 --- a/zconf/chp/chpstat/chpstat.c +++ b/zconf/chp/chpstat/chpstat.c @@ -1270,7 +1270,7 @@ static void cmd_list(void) if (opts.groups & KEY_GRP_METRICS) update_util_all(true); - if (opts.fmt != FMT_JSONSEQ) + if (!util_fmt_is_json_stream(opts.fmt)) util_fmt_obj_start(FMT_LIST, NULL); for (i = 0; opts.forever || i < opts.iterations; i++) { if (i > 0) @@ -1286,7 +1286,7 @@ static void cmd_list(void) * via pipes (e.g. for use with grep). */ fflush(stdout); } - if (opts.fmt != FMT_JSONSEQ) + if (!util_fmt_is_json_stream(opts.fmt)) util_fmt_obj_end(); } @@ -1972,7 +1972,7 @@ static void init_fmt(void) flags |= FMT_FILTER; if (!opts.use_prefix) flags |= FMT_NOPREFIX; - if (opts.fmt == FMT_JSON || opts.fmt == FMT_JSONSEQ) { + if (util_fmt_is_json(opts.fmt)) { /* Ensure correct JSON even if interrupted. */ flags |= FMT_HANDLEINT; }