json-to-bigquery-schema

1.0.0 • Public • Published

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"
      }
    ]
  }
]

Package Sidebar

Install

npm i json-to-bigquery-schema

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

8.05 kB

Total Files

4

Last publish

Collaborators

  • robertbakker