Skip to content

Add --json option to R2 commands in Wrangler #9433

@frankichiro

Description

@frankichiro

Describe the solution

When working with D1 via Wrangler, this option is available:
--json Return output as clean JSON [boolean] [default: false]
but not when working with R2 buckets.

Currently, this command:
wrangler r2 bucket info <bucket-name>
will give me the desired object_count and bucket_size parameters, but not in JSON format.

And this API call:
/accounts/{account_id}/r2/buckets/{bucket_name}
will give me JSON format but not the desired parameters.

This is mysteriously incoherent and should be easy to fix.

I request this feature because it would greatly simplify building local systems that interact with Wrangler, and only using Wrangler as an API, rather than having to build around Wrangler and figure out when to use the Cloudflare API or the GraphQL API or the R2 AWS Api.

Cloudflare offers a lot of functionality through Wrangler, but it would be nice to be allowed to make my own custom workflow for handling many projects in different folders, which is what I'm trying to do, and why this feature would be very helpful.

For my specific use case, I want to make a simple GUI that shows me a list of R2 buckets, and then have the option to select a bucket to see its object count and size. This should be simple, but will now require complicated workarounds with either regex or GraphQL requests, while a simple --json option had solved it for me.

Seeing as this is already a feature for D1 commands, surely it should also be available for R2 commands?

Also, adding the --json parameter should make the output skip this part, and only return the JSON result:

⛅️ wrangler 4.18.0
───────────────────
Listing buckets...

Metadata

Metadata

Labels

enhancementNew feature or requestquick winPotentially easy/straightforward issue to tackler2Relating to R2

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions