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

Re: Pretty output in JSON format

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Sep 24, 2024, 22:06 UTC
Message-ID
<ZvM39VNFptcfwMGk@tapette.crustytoothpaste.net>
In-Reply-To
<CAGW8g7=21pPAgCixjpayEvmw_ns-hcB4e59NP476TKtCRXHPXQ@mail.gmail.com>
On 2024-09-24 at 21:52:35, Ron Ziroby Romero wrote:
Show 19 quoted lines
> Howdy git folk,
> 
> I want to revive the discussion on JSON output. I see a discussion in
> 2021 about it, but it didnt come to a resolution. That discussion was
> talking about adding a --json flag. I have a slightly different
> approach.
> 
> I see online that many people have tried to make various hacks to
> convert git output into JSON, but they all lack completeness,
> especially with log messages with arbitrary text. I believe the best
> and most correct way to get JSON output from git is to add it as a new
> format to the pretty option. Then, it would be easy to pipe the output
> into something like jq to parse the JSON.  Trying to convert git's
> output into JSON is a losing proposition. You've already lost some of
> the context of the output by getting it out of the git program itself.
> A pretty option would provide a standard way to get correct JSON
> output, with git's code handling the weird corner cases.
> 
> What do y'all think?

I think this is ultimately a bad idea. JSON requires that the output be UTF-8, but Git processes a large amount of data, including file names, ref names, commit messages, author and committer identities, diff output, and other file contents, that are not restricted to UTF-8. In fact, despite my recommendation, the trace2 JSON output simply outputs invalid UTF-8, which just doesn't work in nearly any tool, if it encounters such data. We shouldn't add more broken-by-default functionality.

However, if you were interested in CBOR output, which isn't human-readable but is capable of handling byte strings, then I don't see a problem. CBOR is used in FIDO2 and a variety of other protocols and is interoperable, so it should be a fine choice here.

-- 
brian m. carlson (they/them or he/him)
Toronto, Ontario, CA
Previous: Ron Ziroby RomeroNext: Sean Allred
Message 2 of 8 in “Pretty output in JSON format”
  1. Ron Ziroby RomeroSep 24, 2024
  2. brian m. carlsonSep 24, 2024
  3. Sean AllredSep 25, 2024
  4. brian m. carlsonSep 26, 2024
  5. Ron Ziroby RomeroSep 27, 2024
  6. Ron Ziroby RomeroJul 31, 2025
  7. Ron Ziroby RomeroAug 4, 2025
  8. Junio C HamanoAug 4, 2025

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.