git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v9] json_writer: new routines to create JSON data

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Jun 12, 2018, 20:30 UTC
Message-ID
<CAPig+cTMeR-pNtScGwXL=9z-wCLFvioe53ppMOyQ-S-LwQwPig@mail.gmail.com>
In-Reply-To
<20180612202201.94733-2-git@jeffhostetler.com>
On Tue, Jun 12, 2018 at 4:22 PM,  <git@jeffhostetler.com> wrote:
Show 11 quoted lines
> Add "struct json_writer" and a series of jw_ routines to compose JSON
> data into a string buffer.  The resulting string may then be printed by
> commands wanting to support a JSON-like output format.
>
> The json_writer is limited to correctly formatting structured data for
> output.  It does not attempt to build an object model of the JSON data.
>
> 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
s/Linx/Linux/
Show 9 quoted lines
> 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.
>
> Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
> ---
> diff --git a/t/helper/test-json-writer.c b/t/helper/test-json-writer.c
> @@ -0,0 +1,564 @@
> +void get_s(int line_nr, char **s_in)
s/^/static/
Show 7 quoted lines
> +{
> +       *s_in = strtok(NULL, " ");
> +       if (!*s_in)
> +               die("line[%d]: expected: <s>", line_nr);
> +}
> +
> +void get_i(int line_nr, intmax_t *s_in)
s/^/static/
Show 12 quoted lines
> +{
> +       char *s;
> +       char *endptr;
> +
> +       get_s(line_nr, &s);
> +
> +       *s_in = strtol(s, &endptr, 10);
> +       if (*endptr || errno == ERANGE)
> +               die("line[%d]: invalid integer value", line_nr);
> +}
> +
> +void get_d(int line_nr, double *s_in)
s/^/static/
Show 10 quoted lines
> +{
> +       char *s;
> +       char *endptr;
> +
> +       get_s(line_nr, &s);
> +
> +       *s_in = strtod(s, &endptr);
> +       if (*endptr || errno == ERANGE)
> +               die("line[%d]: invalid float value", line_nr);
> +}
Previous: git@jeffhostetler.comNext: Junio C Hamano
Message 3 of 4 in “json_writer V9”
  1. json_writer V9git@jeffhostetler.com, Jun 12, 2018
  2. json_writer: new routines to create JSON datagit@jeffhostetler.com, Jun 12, 2018
  3. Eric SunshineJun 12, 2018
  4. Junio C HamanoJun 12, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.