json2go

command module
v0.0.0-...-aa68db5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2017 License: MIT Imports: 9 Imported by: 0

README

json2go

Travis CI

BigQuery JSON Schema to Go schema converter

json2go --help

     | |/ ____|/ __ \| \ | |      |__ \        |  _ \ / __ \
     | | (___ | |  | |  \| |  ______ ) |_____  | |_) | |  | |
 _   | |\___ \| |  | | . | |  ______/ /______| |  _ <| |  | |
| |__| |____) | |__| | |\  |       / /_        | |_) | |__| |
 \____/|_____/ \____/|_| \_|      |____|       |____/ \___\_\


BigQuery JSON schema to Go schema converter

Version v0.0.1

json2go provides support for converting BigQuery schema from JSON to Go structs

    json2go -schemaFile <file>

$json2go --help

  -packageName string
        name of package (default "main")
  -schemaFile string
        path to file with json schema

It expects schemaFile to contain JSON in format below

[
    {
        "type": "RECORD",
        "name": "data",
        "fields": [
            {
                "type": "BOOLEAN",
                "name": "active"
            },
            {
    
                "name": "ic"
            },
            {
                "type": "INTEGER",
                "name": "id"
            },
            {
                "type": "STRING",
                "name": "name"
            }
        ]
    },
    {
        "type": "INTEGER",
        "name": "numbers"
    },
    {
        "type": "STRING",
        "name": "currency_code"
    }
]

It generate Go struct definition like below,

package main

import "cloud.google.com/go/bigquery"

var schema = bigquery.Schema{
        &bigquery.FieldSchema{
                Name: "data",
                Type: bigquery.RecordFieldType,
                Schema: &bigquery.FieldSchema{
                        Name: "active",
                        Type: bigquery.BooleanFieldType,
                },
                &bigquery.FieldSchema{
                        Name: "ic",
                        Type: bigquery.StringFieldType,
                },
                &bigquery.FieldSchema{
                        Name: "id",
                        Type: bigquery.IntegerFieldType,
                },
                &bigquery.FieldSchema{
                        Name: "name",
                        Type: bigquery.StringFieldType,
                },
        },
        &bigquery.FieldSchema{
                Name: "numbers",
                Type: bigquery.IntegerFieldType,
        },
        &bigquery.FieldSchema{
                Name: "currency_code",
                Type: bigquery.StringFieldType,
        },
}

Installation

go get -u github.com/ceocoder/json2go

Supported BigQuery Field Types

  • BYTES
  • BOOLEAN
  • INTEGER
  • RECORD
  • STRING
  • FLOAT
  • TIMESTAMP
  • DATE
  • TIME
  • DATETIME

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL