JSON to Go Struct

Convert JSON to Go structs with json tags filled in

Runs in your browserUtility02Converters

What is JSON to Go Struct?

This JSON to Go converter infers struct definitions from sample data: field names become exported CamelCase with matching json tags, integers and floats map to int64 and float64, and nested objects are extracted into their own named types. The inference runs entirely in your browser.

How to use JSON to Go Struct

  1. 1Paste a representative JSON response.
  2. 2Enter a name for the root struct.
  3. 3Copy the generated structs and switch optional fields to pointer types to match your backend contract.

Frequently asked questions

Why are integers inferred as int64 rather than int?+

A single sample says nothing about the real range of a JSON number, and int is only 32 bits wide on 32-bit platforms, so large values such as millisecond timestamps or snowflake IDs would overflow. int64 is the safer default, and you can narrow it once you know the range.

How should optional fields be handled?+

One sample cannot distinguish a missing field from a field holding the zero value. When that difference matters, change the field to a pointer type such as *string and add omitempty to its tag, which cleanly separates nil from the empty string.

Related tools

All tools