Problem with order of columns (fields) while loading JSON to BigQuery

Viewed 266

I am working with google script.

I uploaded CSV format data to BigQuery as new table - the column order was preserved.

Now I am uploading JSON data. I checked via Logger.log that the JSON string is in 'correct' order right before calling

let blob = Utilities.newBlob( json, 'application/octet-stream');

  try {
    BigQuery.Jobs.insert(loadJob, projectId, blob);

The file uploads ... but the column order is messed up. I know that for querying that does not really matter... but for human previewing the data it would be nice. (neither it is alphabetical)

1 Answers

I tried using the schema to upload with a given order but I was not able to do it. Instead I asked for a specific order of the columns when I query the table.

This will create the schema in some random order

bigquery.LoadJobConfig(autodetect=True)

Related