JSON to Go Struct Converter Online

Generate reviewable Go struct declarations from one valid JSON sample, including nested objects, arrays, and JSON field tags.

Runs locally
Ready to generate

Paste one valid JSON value to infer its current shape.

159 chars

Objects become structs with json tags; ambiguous sample values use conservative Go types.

0 chars

JSON to Go guide

How to generate Go structs from JSON

Paste one valid JSON value into the converter above, choose a root type name, and generate Go declarations for the structure that is actually present. Objects become structs with exported field names and json tags, while nested objects and stable arrays receive named Go types. Everything runs locally in your browser, so copied API responses and fixtures are not sent to a code-generation service. This tool is free to use. No account or payment is required.

Last updated

What you can do here

  • Nested Go struct generation
  • Exported Go field naming
  • Common Go initialism preservation
  • JSON struct tags
  • Root arrays and primitive type declarations
  • Typed homogeneous arrays
  • Conservative mixed and empty value fallbacks
  • Invalid JSON line and column reporting
  • Browser-local processing

Steps

  1. Paste one valid JSON value into the sample input panel.
  2. Choose an exported root type name such as APIResponse or WebhookEvent.
  3. Select Generate Go and review the inferred scalar, array, and nested struct types.
  4. Copy the generated declarations, then refine optional fields, numeric widths, and domain-specific types in your Go package.

JSON objects become exported Go structs with field tags

Each observed object property becomes an exported Go field. Common initialisms such as ID, URL, API, HTTP, JSON, and UUID follow familiar Go naming conventions, while the original key is preserved in a json struct tag for encoding/json.

Nested objects receive deterministic type names derived from the root type and property path. Arrays with one stable observed item shape use a typed slice, including a named item struct when the array contains objects.

Ambiguous sample values use conservative Go types

One JSON sample cannot prove every production variant. The generator uses int for observed integer numbers, float64 for observed fractional numbers, string and bool for their matching JSON values, and any when the sample does not provide a stable concrete shape.

  • Empty arrays become []any because no item type is present in the sample.
  • Mixed arrays become []any instead of inventing an unsafe union model.
  • Empty objects become map[string]any because no fixed fields are observable.
  • JSON null becomes any because the missing concrete value cannot prove a Go field type.

Treat generated structs as a starting point, not a complete API contract

Generated fields describe the single value you pasted. Review whether production fields can be omitted or null, whether integer widths need int64, and whether strings should become time.Time, custom enums, URLs, decimal types, or other application-specific values.

Parsing and generation happen in the browser. VetaTool does not upload the JSON sample or generated Go source.

JSON to Go struct example

A nested profile becomes its own Go type, common initialisms stay idiomatic, and every field keeps the source JSON key.

Sample JSON

{
  "id": 7,
  "profile": {
    "website_url": "https://example.com"
  },
  "roles": ["admin", "editor"]
}

Generated Go

type APIResponse struct {
  ID int `json:"id"`
  Profile APIResponseProfile `json:"profile"`
  Roles []string `json:"roles"`
}

type APIResponseProfile struct {
  WebsiteURL string `json:"website_url"`
}

Common questions

Frequently asked questions

Does JSON to Go upload my sample?

No. JSON parsing, field naming, type inference, and Go source generation run locally in your browser.

Does the generator create json struct tags?

Yes. Generated struct fields keep their original JSON keys in json tags so encoding/json can map names such as display-name or website_url back to the source payload.

How are JSON numbers mapped to Go?

Observed integers become int and observed fractional values become float64. Review widths and domain-specific numeric types before using generated code in a production contract.

What happens to null, empty arrays, and mixed arrays?

Null becomes any, empty arrays become []any, and arrays containing different observed item shapes become []any because one sample does not provide a safe single concrete type.

Does the converter infer optional fields or time.Time?

No. The first release describes one observed sample and intentionally leaves optionality, date recognition, custom enums, pointers, and richer multi-sample merging for explicit application review.

Debugging a specific JSON issue? Browse JSON troubleshooting.