json-to-bigquery-schema
v1.0.0
Published
Converts any JSON object or array to a Google BigQuery schema
Downloads
2
Maintainers
Readme
json-to-bigquery-schema
This project provides a function to convert an existing JSON-object to a BigQuery JSON schema file. It tries its best to guess data types based on the given input by merging lists of objects and using regular expressions.
usage
import jsonToBigquery from "json-to-bigquery-schema"
const jsonString = `{
"year": 1977,
"title": "Star Wars original trilogy/Cast",
"items": [
{
"type": "actor",
"name": "Carrie Fisher"
},
{
"actor": "Mark Hamill",
"character": "Luke Skywalker"
},
"R2D2 is a name, this string will be superseded by the previous object in the array"
]
}`;
const obj = JSON.parse(jsonString);
Output:
[
{
"name": "year",
"type": "INTEGER"
},
{
"name": "title",
"type": "STRING"
},
{
"name": "items",
"type": "RECORD",
"mode": "REPEATED",
"fields": [
{
"name": "type",
"type": "STRING"
},
{
"name": "name",
"type": "STRING"
},
{
"name": "actor",
"type": "STRING"
},
{
"name": "character",
"type": "STRING"
}
]
}
]