mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
libutil/util_fmt: Introduce JSON Lines text format
JSON Lines text format (JSONL) [1] is a line-delimited JSON format where objects are separated by the new line character (\n, LF) as opposed to the JSON Sequence text format (json-seq) where JSON text is encapsulated in an ASCII Record Separator (0x1E, RS) and ASCII Line Feed character (0x0A, LF). Whilst JSONL is also used for data streaming, this simpler format is better suited for logging and works also well with traditional line-oriented Unix tooling (e.g. grep or sed). Add this format to util_fmt so that users have more choice and control over formats that are required for their usecases. Add helper functions that let the user determine whether a given format type is JSON in general or a JSON streaming format (such as json-seq or jsonl). For better readability and more clarity use the helper function util_fmt_is_json_stream() where the same decision is made for both JSON streaming formats FMT_JSONSEQ and FMT_JSONL. [1] https://jsonlines.org/ Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com> Reviewed-by: Niklas Schnelle <schnelle@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
@@ -193,6 +193,9 @@ int main(int UNUSED(argc), char *UNUSED(argv[]))
|
||||
announce("JSON formatted as sequence");
|
||||
simple_example(FMT_JSONSEQ, FMT_DEFAULT);
|
||||
|
||||
announce("JSON Lines format");
|
||||
simple_example(FMT_JSONL, FMT_DEFAULT);
|
||||
|
||||
announce("Pairs output");
|
||||
simple_example(FMT_PAIRS, FMT_KEEPINVAL);
|
||||
|
||||
@@ -232,6 +235,9 @@ int main(int UNUSED(argc), char *UNUSED(argv[]))
|
||||
announce("JSON sequence output with meta-data");
|
||||
meta_example(FMT_JSONSEQ);
|
||||
|
||||
announce("JSON Lines output with meta-data");
|
||||
meta_example(FMT_JSONL);
|
||||
|
||||
announce("Pairs output with meta-data");
|
||||
meta_example(FMT_PAIRS);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user