script.sh

1
2
3
4
5
6
7
8
#!/bin/bash
set -eu
PROJECT_ID=myproject
DATASET_NAME=temp
TABLE_NAME=$(basename $1 | sed 's/\.[^\.]*$//')
bq load --autodetect --source_format=NEWLINE_DELIMITED_JSON ${PROJECT_ID}:${DATASET_NAME}.${TABLE_NAME} $1
bq show --schema --format=prettyjson ${PROJECT_ID}:${DATASET_NAME}.${TABLE_NAME} > ${TABLE_NAME}.json
bq rm -f -t ${PROJECT_ID}:${DATASET_NAME}.${TABLE_NAME}
1
$ ./script.sh /path/to/mydata.jsonl

以下のファイルが出力される

./mydata.json

1
2
3
4
5
6
7
8
[
  {
    "mode": "NULLABLE",
    "name": "id",
    "type": "INTEGER"
  }
  ...
]

もっといい方法ありそう