Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

A BigQuery table has schema which can be viewed in the web UI, updated, or used to load data with the bq tool as a JSON file. However, I can't find a way to dump this schema from an existing table to a JSON file (preferably from the command-line). Is that possible?

like image 393
Daniel Waechter Avatar asked Apr 03 '17 22:04

Daniel Waechter


People also ask

Can BigQuery store JSON?

BigQuery natively supports JSON data using the JSON data type. This document describes how to create a table with a JSON column, insert JSON data into a BigQuery table, and query JSON data.

Can I export data from BigQuery?

After you've loaded your data into BigQuery, you can export the data in several formats. BigQuery can export up to 1 GB of data to a single file. If you are exporting more than 1 GB of data, you must export your data to multiple files. When you export your data to multiple files, the size of the files will vary.


1 Answers

a way to dump schema from an existing table to a JSON file (preferably from the command-line). Is that possible?

try below

bq show bigquery-public-data:samples.wikipedia   

You can use –format flag to prettify output

--format: none|json|prettyjson|csv|sparse|pretty:

Format for command output. Options include:

none:       ... pretty:     formatted table output   sparse:     simpler table output   prettyjson: easy-to-read JSON format   json:       maximally compact JSON   csv:        csv format with header    

The first three are intended to be human-readable, and the latter three are for passing to another program. If no format is selected, one will be chosen based on the command run.

Realized I provided partial answer :o)

Below does what PO wanted

bq show --format=prettyjson bigquery-public-data:samples.wikipedia | jq '.schema.fields'  
like image 102
Mikhail Berlyant Avatar answered Oct 13 '22 04:10

Mikhail Berlyant