Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does gsutil cli tool support JSON output?

Tags:

bash

gsutil

gsutil produces stdout output in it's custom key-value format which is quite inconvenient to parse. Is it possible to make gsutil generate JSON instead e.g. for this command:

gsutil ls -L gs://bucket-name/relative/path
like image 534
mechatroner Avatar asked Sep 14 '25 23:09

mechatroner


1 Answers

The output will be in something that is closer to be yaml format. as mentioned in the code on the official GitHub repository and as part of gsutil the output format cannot be modified.

the output will be something like:

 gs://bucket/ :
            Storage class:                STANDARD
            Location constraint:          US
            Versioning enabled:           False
            Logging configuration:        None
            Website configuration:        None
            CORS configuration:           None
            Lifecycle configuration:      None
            Requester Pays enabled:       True
            Labels:                       None
            Default KMS key:              None
            Time created:                 Thu, 14 Jan 2016 19:25:17 GMT
            Time updated:                 Thu, 08 Jun 2017 21:17:59 GMT
            Metageneration:               1
            Bucket Policy Only enabled:   False
            ACL:
              [
                {
                  "entity": "project-owners-867489160491",
                  "projectTeam": {
                    "projectNumber": "867489160491",
                    "team": "owners"
                  },
                  "role": "OWNER"
                }
              ]
            Default ACL:
              [
                {
                  "entity": "project-owners-867489160491",
                  "projectTeam": {
                    "projectNumber": "867489160491",
                    "team": "owners"
                  },
                  "role": "OWNER"
                }
              ]

To get this as JSON i found this go repository that can work for encode the output as a JSON

git clone https://github.com/fedir/json_encode.git
cd json_encode
go build

gsutil ls -L gs://bucket-name  | ./json_encode

like image 125
Soni Sol Avatar answered Sep 16 '25 13:09

Soni Sol