Skip to content

json: support BORG_JSON_COMPACT env var for single-line output#9855

Merged
ThomasWaldmann merged 6 commits into
borgbackup:masterfrom
charmikadi:fix/json-compact-env-var
Jul 5, 2026
Merged

json: support BORG_JSON_COMPACT env var for single-line output#9855
ThomasWaldmann merged 6 commits into
borgbackup:masterfrom
charmikadi:fix/json-compact-env-var

Conversation

@charmikadi

Copy link
Copy Markdown
Contributor

Description

When BORG_JSON_COMPACT is set, json_dump() produces single-line JSON instead of the default indented output. This makes it easier for log collectors to parse borg's JSON stdout as one event per line. Implementation uses an env var and not CLI flag.

Fixes #3605

Checklist

  • PR is against master
  • New code has tests and docs where appropriate
  • Tests pass (run tox or the relevant test subset)
  • Commit messages are clean and reference related issues

@codecov

codecov Bot commented Jul 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.13%. Comparing base (5aaa2dd) to head (c322dd5).
⚠️ Report is 9 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9855      +/-   ##
==========================================
+ Coverage   85.11%   85.13%   +0.01%     
==========================================
  Files          93       93              
  Lines       15408    15421      +13     
  Branches     2326     2329       +3     
==========================================
+ Hits        13114    13128      +14     
+ Misses       1596     1595       -1     
  Partials      698      698              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@charmikadi charmikadi marked this pull request as ready for review July 4, 2026 05:33
Comment thread src/borg/helpers/parseformat.py Outdated
@Goddesen

Goddesen commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Maybe not directly relevant to this PR, but might as well put it here: JSON output is meant to be read programmatically, right? Why isn't it default to output the most compact form possible to spare the extra work? Users can set the indent envvar or pipe into jq for readable output if that's what they want.

@ThomasWaldmann

Copy link
Copy Markdown
Member

@Goddesen good idea, guess we could change the default for borg2.

@ThomasWaldmann ThomasWaldmann merged commit cef78c9 into borgbackup:master Jul 5, 2026
19 checks passed
@ThomasWaldmann

Copy link
Copy Markdown
Member

@charmikadi Thanks!

Can you please do a backport to 1.4-maint branch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No indent option on --json and --log-json

3 participants