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

Re: Pretty output in JSON format

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 4, 2025, 21:19 UTC
Message-ID
<xmqqldny4wfn.fsf@gitster.g>
In-Reply-To
<CAGW8g7kMVqsi6+JkdjDS-czKJQ=01ULUz36sZrGom+QPVtRF3A@mail.gmail.com>
Ron Ziroby Romero <ziroby@gmail.com> writes:
> First, I'm questioning my approach of hacking pretty.c with a series
> of 'if json' blocks. Would it be better to make a new file,
> json-log.c, and divorce myself from the pretty flow entirely?
The same question to the other thread applies: why json?

If the objective is to give a parseable output for machines to robustly read, then I do not think you want to use any of the infrastructure laid by and for the pretty_print_commit() function, whose purpose is quite the opposite, like squeezing inter paragraph spaces, trimming trailing whitespaces, indenting even an empty line by 4 spaces, etc., etc.

> Second, I see that someone is adding a --json flag to git status[1]. I
> figure that argues for git log to use the --json flag. I don't think
> that affects me other than making the case for this JSON output.
Please don't.

That other thread is getting discouraged from introducing a new option just for a single new format. Unfortunately "status" does not have the --format={short,long,...} so we need to add one new option to allow new formats to be added in a more generic way, but once that is done, the next new format would not have to add a new option. Compared to it, "log" already has --pretty={...}, so we do not have to add --json just for this single format, which makes us luckier than the other thread.

Previous: Ron Ziroby Romero
Message 8 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.