JSON Input

Go Output

What Is JSON to Go?

You've just hit a REST API in Postman, the response is JSON, and you need to unmarshal it in Go — but writing the struct by hand for a deeply nested response is genuinely annoying. JSON and Go's encoding/json package work beautifully together, but Go requires explicit struct definitions for every nested object. Miss a field or get a type wrong and your unmarshal silently returns zero values. This tool generates the complete struct tree from your JSON so you can paste it straight into your project.

This tool generates Go structs from your JSON. Set the struct name and package in the config panel. Enable JSON tags for json:"field_name" so the struct fields map correctly to camelCase or snake_case keys. Enable pointers for optional or nullable fields so you can distinguish between zero value and absent. The output is ready to paste into your project and use with json.Unmarshal().

Conversion runs entirely in your browser. Your JSON is never sent to a server. You can confirm this by opening your browser's Network tab while using the tool.

How to Use This Tool

1

Paste or Upload JSON

Start by putting an API response in the left pane, either pasted or read from a .json / .txt file via Upload. Use the Sample button to load example data if you want to test things out. In the config panel, set the struct name (e.g. User) and package name (e.g. models). Enable JSON Tags for json:"key" struct tags. Enable Pointers for optional or nullable fields.

2

Review the Generated Structs

The right panel shows the generated Go structs. Nested objects become nested or separate structs. Arrays become []Type. JSON tags map struct fields to JSON keys. Use json.Unmarshal(data, &v) to parse your JSON into the struct. If your JSON has invalid syntax, fix it first using the JSON Formatter or JSON Validator.

3

Copy or Download

The struct definitions go to your clipboard with Copy, while Download writes them to a .go file you can drop into your module. You may need to add imports or adjust package names depending on your project structure.

JSON to Go Examples

Here is an example of generating Go structs from a JSON object.

Example: Subscriber record

JSON input:

Input

Generated Go output:

Output

When JSON to Go Helps

Most developers end up needing this when integrating with APIs. You send a request through Postman or curl, and the response comes back as JSON. Pasting it here gives you typed structs you can use immediately with encoding/json. For pulling out specific values from large responses, jq works well from the command line.

Config files are another common case. A config.json or settings.json with nested objects often needs a Go struct for type-safe access. If you need to merge two JSON files first, there's a separate JSON Merge tool for that.

Database exports from MongoDB, Firestore, or CouchDB are typically large JSON blobs. Running them through here helps you understand the document structure and generate Go structs for import scripts or queries.

Frequently Asked Questions

How do I generate Go structs from JSON automatically?

Paste your JSON into this tool and it generates Go structs instantly. Enable JSON Tags so field names map correctly to JSON keys. Drop the generated types into your package and hand them to json.Unmarshal().

Why do Go structs need JSON tags?

Go struct field names must be exported (capitalized) for JSON. JSON often uses camelCase or snake_case. The json:"fieldName" tag tells encoding/json which JSON key maps to which struct field. Without tags, json.Unmarshal does case-insensitive matching, which can silently miss fields.

Is my data sent anywhere?

No. The struct generator is plain JavaScript on this page, so the payload you paste is never uploaded. The Network tab in DevTools stays quiet while it works, which makes it fine for real production responses.

What about omitempty?

Add omitempty to the JSON tag for fields you don't want in the output when empty: json:"name,omitempty". The generator doesn't add it by default because whether you want omitempty depends on your use case — edit the output after generating.

When should I use pointers for struct fields?

Use *Type for optional or nullable fields. With a pointer, a missing JSON field results in nil, which you can check. Without pointers, a missing field gives you the zero value (e.g. 0, ""), and you can't tell if it was absent or just empty.

Related Tools

For Go JSON handling, see encoding/json. For JSON, see the JSON specification and RFC 8259. For a general overview, see MDN JSON. For API testing, see Postman. For Go struct tags, see the Go spec. See also jq for JSON processing.