Skip to content

JSON to Go — Generate Structs from JSON Online

Paste JSON and instantly get Go struct definitions with typed fields, json tags, and PascalCase naming.

Last updated:

Why generate Go structs from JSON

Go is a statically typed language, so consuming JSON from external APIs requires well-defined structs. Writing these by hand is slow, repetitive, and easy to get wrong — especially when the payload is deeply nested or contains dozens of fields. This tool eliminates the boilerplate:

  • API integration — paste a sample JSON response from any REST or GraphQL endpoint and get the Go structs you need for encoding/json unmarshaling in seconds.
  • Rapid prototyping — scaffold data models for a new microservice or CLI tool without writing boilerplate. Focus on business logic instead of type definitions.
  • Language migration — moving from Python, JavaScript, or Ruby to Go? Convert the JSON your existing service produces into idiomatic Go types as a starting point.
  • Documentation — generate struct definitions from example payloads to include in API docs, READMEs, or design documents.

Go naming conventions

Go has strict conventions around identifier naming that differ from JSON's typical camelCase or snake_case keys. This tool automatically applies the correct transformations:

  • Exported fields — struct fields must start with an uppercase letter to be visible outside the package. The tool converts keys like first_name to FirstName (PascalCase).
  • Common abbreviations — Go style guidelines treat certain abbreviations as whole words. For example, id becomes ID, url becomes URL, and http_response becomes HTTPResponse.
  • Struct names — nested JSON objects produce separate named structs derived from the parent key, keeping the type hierarchy clean and reusable.

These conventions come from the official Go code review comments and are enforced by linters like golint and revive. The generated code follows them out of the box.

Struct tags explained

Go uses struct tags — metadata strings attached to fields — to control how encoding/json marshals and unmarshals data. Every generated field includes the appropriate tag:

  • json:"field_name" — maps the Go field to the original JSON key. Without this tag, json.Unmarshal would only match keys that exactly match the Go field name (case-insensitive), which breaks for snake_case or unusual key names.
  • omitempty — when added (e.g. json:"name,omitempty"), the field is omitted from marshaled output if it holds its zero value. Useful for optional fields in request bodies.
  • Marshaling round-trip — with correct struct tags, you can unmarshal a JSON response into a Go struct and marshal it back without losing any field mappings, even when the JSON key format differs from Go conventions.

The tag syntax is `json:"key_name"` using backtick-delimited raw strings. Multiple tags (e.g. json and db) can be combined in the same backtick string, separated by spaces.

Related code generation tools

  • JSON to C# — generate C# classes or records from JSON for .NET projects.
  • JSON to TypeScript — generate TypeScript interfaces from JSON for type-safe frontend and Node.js code.
  • JSON Schema Generator — generate a JSON Schema definition from sample data for validation and documentation.
  • JSON Formatter — format, validate, and minify JSON before converting it.

Frequently Asked Questions

What Go types does it generate?
string for JSON strings, int for whole numbers, float64 for decimals, bool for booleans, interface{} for null/unknown, and typed slices for arrays.
How are field names converted?
JSON keys are converted to Go's PascalCase convention. Common abbreviations like id, url, api, http are uppercased (ID, URL, API, HTTP) following Go naming conventions.
What are json struct tags?
Tags like json:"name" tell Go's encoding/json package which JSON key maps to which struct field. This tool generates them automatically.
What does omitempty do?
Adding omitempty to a json tag means the field is omitted from JSON output if it has a zero value (empty string, 0, false, nil). Useful for optional fields.
Does it handle nested objects?
Yes. Each unique nested object shape gets its own named struct. Identical shapes are deduplicated.
Is my data safe?
Yes. This tool runs entirely in your browser. Your JSON is never sent to any server.

Related Tools