routines to generate JSON data
PATCH v5 1/1 routines to generate JSON data
From: Jeff Hostetler <[email protected]>
This is version 5 of my JSON data format routines.
This version address the uint64_t vs intmax_t formatting issues that were discussed on the mailing list. I removed the jw_*_int() and jw_*_uint64() routines and replaced them with a single jw_*_intmax() routine.
Also added a jw_release() routine similar to strbuf_release() and fixed the indentation of sub-array when pretty printing is enabled.
The following PR includes my WIP telemetry changes that build upon the json-writer routines and demonstrates how they might be used. The first commit in this PR is this patch.
https://github.com/jeffhostetler/git/pull/11
Jeff Hostetler (1):
json_writer: new routines to create data in JSON format
Makefile | 2 + json-writer.c | 394 ++++++++++++++++++++++++++++++ json-writer.h | 91 +++++++ t/helper/test-json-writer.c | 572 ++++++++++++++++++++++++++++++++++++++++++++ t/t0019-json-writer.sh | 253 ++++++++++++++++++++ 5 files changed, 1312 insertions(+) create mode 100644 json-writer.c create mode 100644 json-writer.h create mode 100644 t/helper/test-json-writer.c create mode 100755 t/t0019-json-writer.sh
Signature · 1 line
2.9.3
PATCH v5 1/1 json_writer: new routines to create data in JSON format
From: Jeff Hostetler <[email protected]>
Add a series of jw_ routines and "struct json_writer" structure to compose JSON data. The resulting string data can then be output by commands wanting to support a JSON output format.
The json-writer routines can be used to generate structured data in a JSON-like format. We say "JSON-like" because we do not enforce the Unicode (usually UTF-8) requirement on string fields. Internally, Git does not necessarily have Unicode/UTF-8 data for most fields, so it is currently unclear the best way to enforce that requirement. For example, on Linx pathnames can contain arbitrary 8-bit character data, so a command like "status" would not know how to encode the reported pathnames. We may want to revisit this (or double encode such strings) in the future.
The initial use for the json-writer routines is for generating telemetry data for executed Git commands. Later, we may want to use them in other commands, such as status.
--- Makefile | 2 + json-writer.c | 394 ++++++++++++++++++++++++++++++ json-writer.h | 91 +++++++ t/helper/test-json-writer.c | 572 ++++++++++++++++++++++++++++++++++++++++++++ t/t0019-json-writer.sh | 253 ++++++++++++++++++++ 5 files changed, 1312 insertions(+) create mode 100644 json-writer.c create mode 100644 json-writer.h create mode 100644 t/helper/test-json-writer.c create mode 100755 t/t0019-json-writer.sh
Makefile +2 -0
@@ -662,6 +662,7 @@ TEST_PROGRAMS_NEED_X += test-fake-ssh TEST_PROGRAMS_NEED_X += test-genrandom TEST_PROGRAMS_NEED_X += test-hashmap TEST_PROGRAMS_NEED_X += test-index-version +TEST_PROGRAMS_NEED_X += test-json-writer TEST_PROGRAMS_NEED_X += test-lazy-init-name-hash TEST_PROGRAMS_NEED_X += test-line-buffer TEST_PROGRAMS_NEED_X += test-match-trees
@@ -815,6 +816,7 @@ LIB_OBJS += hashmap.o LIB_OBJS += help.o LIB_OBJS += hex.o LIB_OBJS += ident.o +LIB_OBJS += json-writer.o LIB_OBJS += kwset.o LIB_OBJS += levenshtein.o LIB_OBJS += line-log.o
json-writer.c new file +394 -0
394 lines not on this page · raw message
json-writer.h new file +91 -0
91 lines not on this page · raw message
t/helper/test-json-writer.c new file +572 -0
572 lines not on this page · raw message
t/t0019-json-writer.sh new file +253 -0
253 lines not on this page · raw message
Signature · 1 line
2.9.3
Re: [PATCH v5] json_writer: new routines to create data in JSON format
Quoted 6 lines · On Tue, Mar 27, 2018 at 2:02 PM <[email protected]> wrote:
From: Jeff Hostetler <[email protected]>
Add a series of
jw_routines and "structjson_writer" structure to compose JSON data. The resulting string data can then be output by commands wanting to support a JSON output format.
<snip>
json-writer.c line 168
Quoted 7 lines
void
jw_object_intmax(struct json_writer *jw, const char *key, intmax_t value)json-writer.c new file +3
-0+{ +object_common (jw, key); +strbuf_addf (&jw->json,"%" PRIdMAX, (intmax_t )value);
Cast is not necessary.
Quoted 2 lines
(quoted diff) +2
-0+} +
<snip>
json-writer.c line 306
Quoted 5 lines
json-writer.c new file +4
-0+void jw_array_intmax (struct json_writer *jw,intmax_t value) +{ +array_common (jw); +strbuf_addf (&jw->json,"%" PRIdMAX, (intmax_t )value);
Cast is not necessary
Review
Quoted 3 lines
(quoted diff) +2
-0+} +
<snip>
-- Wink