workers-sdk
workers-sdk copied to clipboard
[wrangler] Add --json flag to r2 bucket info command
What
Adds a --json flag to the wrangler r2 bucket info command, returning the bucket info in clean JSON format.
Why
Fixes #9433 — The current output is not machine-readable. Adding this makes the output usable in scripts and consistent with D1 commands that already support --json.
How
- Adds a
--jsonflag tor2 bucket info - Omits verbose output when
--jsonis passed - Adds a unit test verifying valid JSON output
Test Plan
- ✅
pnpm exec vitest run packages/wrangler/src/__tests__/r2/bucket.test.tspassed - ✅ Manual output verified
Notes
Currently, the banner line (⛅ wrangler 4.18.0) still appears even when using --json.
I left it in earlier to avoid blocking the main feature, but it has now been suppressed when --json is passed for cleaner machine-readable output.
Example
With --json:
$ wrangler r2 bucket info my-bucket-name --json
(⛅️ wrangler 4.18.0\n──────────────────)
{
"name": "my-bucket-name",
"created": "2025-06-07T15:55:22.222Z",
"location": "APAC",
"default_storage_class": "Standard",
"object_count": "0",
"bucket_size": "0 B"
}
Without --json:
$ wrangler r2 bucket info my-bucket-name
(⛅️ wrangler 4.18.0\n──────────────────)
Bucket Name: my-bucket-name
Created At: 2025-06-07T15:55:22.222Z
Location: APAC
Storage Class: Standard
Object Count: 0
Size: 0 B
Edit (June 12, 2025)
Implemented the requested change to suppress the banner (⛅ wrangler 4.18.0) when --json is used.
$ wrangler r2 bucket info my-bucket-name
{
"name": "my-bucket-name",
"created": "2025-06-07T15:55:22.222Z",
"location": "APAC",
"default_storage_class": "Standard",
"object_count": "0",
"bucket_size": "0 B"
}