Back to blog

Go, quicktype!

quicktype can now output Go in addition to C#.

quicktype can now output Go in addition to C#.

Example: Latest Bitcoin block

For example, here's the JSON for the latest Bitcoin block from blockchain.info/latestblock:

{
  "hash": "0000000000000000001b8a6e8b...",
  "time": 1500098276,
  "block_index": 1734892,
  "height": 476244,
  "txIndexes": [...]
}

Generate typed Go code

Using the quicktype command (available via npm i -g quicktype), we can generate strongly typed Go code for working with this Bitcoin data:

$ quicktype -o latest_block.go --lang go blockchain.info/latestblock

This creates the file latest_block.go with the following Go code:

package main

type LatestBlock struct {
    Hash       string  `json:"hash"`
    Time       int64   `json:"time"`
    BlockIndex int64   `json:"block_index"`
    Height     int64   `json:"height"`
    TxIndexes  []int64 `json:"txIndexes"`
}

Play with it

Visit quicktype.io to try it out. We eagerly await your feedback!