JSON Input

Go Output

What Is JSON to Go?

Go uses structs for structured data. When you unmarshal JSON with encoding/json, you need structs with matching fields and types. The JSON specification defines objects, arrays, strings, numbers, and booleans—but Go needs explicit struct definitions for each nested object. Writing those by hand is tedious and error-prone when the JSON is large or complex.

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

Copy your JSON and paste it into the left editor. You can also click Upload to load a .json or .txt file from your computer. 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

Use Copy to put the result on your clipboard, or Download to save it as a .go file. Paste into your Go project. 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, the JSON Path tool works well alongside this.

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

Why JSON tags?

Go struct field names must be exported (capitalized) for JSON. JSON often uses camelCase or snake_case. The json:"fieldName" tag maps the struct field to the JSON key. Enable JSON Tags in the config so the generated structs work correctly with json.Unmarshal and json.Marshal.

Pointers for optional fields?

If a JSON field can be null or missing, use *Type so you can distinguish between zero value (e.g. empty string) and absent. Without pointers, you can't tell the difference. Enable Use Pointers in the config for optional or nullable fields.

Is my data sent anywhere?

No. Generation runs entirely in your browser using JavaScript. No data is sent to any server. You can confirm this by opening your browser's Network tab while using the tool.

What about omitempty?

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

Interface{} for dynamic JSON?

For unknown or highly variable structure, use map[string]interface{} or interface{}. This tool generates typed structs for known shapes. If your JSON structure changes frequently, you may prefer interface{}.

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.