JSON to Go Struct

Generate Go struct declarations from a representative JSON object or array, including nested types, exported field names, and original-property json tags.

Choose the package and root type names, then generate a complete Go source file with valid exported fields and original-property json tags. Review sample-dependent choices before using the types in an application.

How JSON values map to Go types

How to generate Go structs from JSON

  1. Paste a JSON object or non-empty array, or load the sample data.
  2. Choose the package and root type names, and whether json tags should include omitempty.
  3. Generate the Go source, review the inferred types, then copy or download the result.

JSON to Go struct FAQ

What JSON input can I use?

Use one JSON object or any non-empty JSON array. A top-level array becomes a named slice, and every object item in an array contributes to the inferred fields. Property names must be representable by Go's standard encoding/json struct tags; unsupported names produce an error instead of being silently changed.

How are object arrays and missing fields handled?

Object arrays are merged across all supplied items. A field seen in only some items is still generated from the values that are present. The omitempty option changes every json tag; it does not add pointers or validate required fields.

What happens to null and mixed values?

A null value, an incompatible mixture of value types, or an array containing incompatible values becomes any. An empty array becomes []any because the sample does not reveal its element type.

Can I use the generated types without reviewing them?

Treat the result as a sample-based starting point. Check optional fields, time strings, map-like objects, numeric ranges, and identifiers that may exceed the exact range of a JSON number before adding the types to your project.

Is my JSON uploaded?

No. The JSON is parsed and converted in this browser tab by this tool. It is not uploaded to a server.

Related tools: JSON Formatter · JSON to TypeScript · JSON Schema Generator