Skip to content

Instantly share code, notes, and snippets.

@rubenvarela
Created November 19, 2022 02:36
Show Gist options
  • Save rubenvarela/a998dfeab9a1c65a9239bcc6a8318bc7 to your computer and use it in GitHub Desktop.
Save rubenvarela/a998dfeab9a1c65a9239bcc6a8318bc7 to your computer and use it in GitHub Desktop.
BigQuery - JSON schema to basic Python Schema
#!/usr/bin/env python3
import sys
import json
# used as
# bq show --schema --format=prettyjson PROJECT:DATASET.TABLE | ./main.py
data = ""
for x in sys.stdin:
data = data + x
loaded_data = json.loads(data)
for item in loaded_data:
print(f'bigquery.SchemaField("{item["name"]}", "{item["type"]}"),')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment