Sachiko
Sachiko

Reputation: 924

Is there any way to export a BigQuery table's schema as YAML?

I understand we can export table schema info in JSON format by 'bq show' command in GCP, but don't know how to export to yaml file.

Is there any way to convert schema info to yaml file automatically? Our table's structure is a bit complicated and target tables are so much.

Upvotes: 1

Views: 614

Answers (1)

ppuschmann
ppuschmann

Reputation: 235

You could use the tool yq for this task.

Homepage of yq

Example:

bq show --schema --format=prettyjson [PROJECT_ID]:[DATASET].[TABLE] | yq -p json -o yaml

This command pipes the output of the bq command to yq which reads the json-input and exports to yaml.

Upvotes: 2

Related Questions