Pocket Gophers

Generating Go structs from JSON

2017-12-07

At times the JSON you want to work with in Go can have large numbers of elements in objects and/or deeply nested objects of different types. Manually writing the appropriate Go structs that correctly unmarshal and marshal the JSON can become tedious and error prone.

The following tools automate this process by generating Go structs from a sample of the JSON the Go code needs to handle.

JSON to Go Struct

Website based on JSON-to-Go that includes tools to prettify the JSON and fetch JSON from a URL along with other JSON conversion utilities.

JSON-to-Go

Website where you paste in an example of the JSON you need to parse. The site will generate the Go struct(s) (with tags) that will work for that JSON.

gojson

Command line tool and package that generates a Go struct that will work for the example JSON given to it.

jflect

Command line tool that takes the JSON given to it on stdin and writes a compatible Go struct on stdout.

jsonfiddle

Multifunction command line tool that can:


As I find more tools, I will update this page. To be notified when this page is updated, please subscribe.

Dig into the Fundamentals of Go

Subscribe to receive a weekly email covering a Go fundamental. Be it the language, its tooling, or its packages, you will learn what you need to know.