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'
Alternatively use INFORMATION_SCHEMA.<something> with other views to get different meta info to JSON.
As @Michel Hua said in their answer, select Query results -> JSON in bigquery to get JSON after running the SQL query
SELECT table_name, ARRAY_AGG(STRUCT(column_name, data_type, description)) as columns
FROM `your-project-id`.your_dataset.INFORMATION_SCHEMA.COLUMN_FIELD_PATHS
WHERE table_name = 'your_table_name'
GROUP BY table_name