GO

JSON to Go Struct

Infer nested Go structs, JSON tags, slices, pointers, and optional fields from samples

JSON & Data
🔒 100% client-side — your data never leaves this page
Maintained by ToolsKit Editorial TeamUpdated: August 23, 2026Reviewed: August 23, 2026
JSON → Go structs

Optional fields are inferred from missing and null values across object samples. Mixed types fall back to a generic type; review the result against the real API contract.

Go structs

Generated Go structs will appear here.

About this tool

JSON to Go Struct infers named Go models from one JSON object or a non-empty array of object samples. Nested objects become separate structs, arrays become slices, integral samples use int64, decimal samples use float64, and mixed values fall back to any. When multiple objects are supplied, a field becomes optional if it is missing or null in any sample; optional scalar and object fields can use pointers and json tags can include omitempty. Generated names are sanitized and duplicate normalized field names receive suffixes. Inference cannot discover time.Time, custom numeric widths, enums, validation rules, or domain-specific interfaces, so compile and review the result in the target module.

Scenario Recipes

01

Bootstrap response structs from captured API samples

Goal: Create a reviewable starting point without losing optionality seen across records

  1. Paste several representative response objects as one JSON array.
  2. Choose a domain-specific root name and decide whether optional fields need pointers and omitempty.
  3. Generate the structs, then replace generic types and strings with domain enums, time values, and validated custom types before compiling.

Result: A nested Go model set that reflects observed fields while leaving contract decisions explicit.

Frequently Asked Questions

Can it infer optional fields from an array of samples?

Yes. A key missing or null in any object sample becomes optional.

When are pointers generated?

With the option enabled, optional scalar and nested-object fields use pointers; slices and any remain naturally nullable.

How are JSON numbers mapped?

Whole-number samples use int64, samples with decimals use float64, and mixed incompatible types use any.

Are nested objects generated as separate structs?

Yes. Property names become model-name candidates and collisions receive deterministic numeric suffixes.

Will it infer time.Time or enums?

No. Strings remain strings and business constraints require review against the API contract.

Is sample JSON uploaded?

No. Parsing, type inference, naming, and Go code generation run locally.

Keep browsing