GoogleCloudPlatform / gsutil

A command line tool for interacting with cloud storage services.
Apache License 2.0
874 stars 334 forks source link

Support JSON output #1099

Open mechatroner opened 4 years ago

mechatroner commented 4 years ago

Please, consider adding support for json output which can be enabled with a CLI option or an environment variable. It would be especially beneficial for 'gsutil ls -L gs://bucket/object/path' command which currently produces output in a custom format which is hard to parse. BTW aws cli tool which provides similar functionality can produce JSON output in aws s3api list-objects mode (and probably does this by default)

bukzor commented 3 years ago

The output of gsutil retention get is particularly useless without json. There's no clean way to create the matching retention set command from the output of retention get.

DSdatsme commented 1 year ago

[Workaround] For my automation script, I need to fetch some metadata(Content-Length) from gsutil stat command. Since the output is in yaml format, I am using yq to parse whatever I need. Eg:

OBJECT_PATH=gs://example-bucket/test.txt
gsutil stat $OBJECT_PATH | yq e ".\"$OBJECT_PATH\".Content-Length"

If you need it in JSON use yq -o=json, also works for gsutil ls command.

dilipped commented 1 year ago

I would encourage giving gcloud storage a try. It has the ls command which is equivalent to the gsutil ls command and provides a --json flag for JSON output. https://cloud.google.com/sdk/gcloud/reference/storage/ls