1001Ferramentas
🐹 Converters

JSON to Go Struct

Convert a JSON to a Go struct with `json:` tags and inferred types. Detects strings, ints, floats, bools, slices and nested structs. Everything in your browser.

How it works

Every JSON key becomes a struct field in PascalCase, since Go only serialises exported fields — the ones starting with a capital letter. The json:"..." tag keeps the original key around so that encoding/json still maps it correctly.

Types are inferred automatically: whole numbers become int, decimals become float64, arrays with a single element type become []T, and mixed or null arrays fall back to interface{}. Everything runs in your browser.

From JSON payload to a tagged struct

An API response landed on your desk and now you need the matching Go struct. Typing it by hand is tedious and treacherous: one typo in a json: tag and encoding/json says nothing at all, it just hands back the field's zero value, and you spend the afternoon wondering why created_at is empty. Paste the JSON, name the root type, and the struct comes out ready to drop into the file.

Every key becomes a PascalCase field, because Go only serializes exported fields, the ones starting with a capital, and the json: tag keeps the original name. Types are inferred from the sample values: whole numbers become int, decimals become float64, null becomes interface{}. That is where the trap sits. JSON does not separate integers from decimals, so a price that arrived as 10.0 is read as int and breaks on the first response carrying 10.5.

For arrays, leave a single representative element before pasting. With two or more objects in the same list the generator emits one struct per element (Post, Post2) and the field falls back to []interface{}. Keys that clash with a Go keyword or start with a digit pick up an underscore, becoming _Type or _2fa, and an underscore-initial field is unexported, so rename it before you compile. Everything runs in the browser.

Frequently asked questions

Why did my decimal field come out as int?
Because in the sample it arrived without a fractional part, as 10.0 or 0. Change it to float64 in the struct, or paste an example with a real decimal value.
Does it generate pointers and omitempty?
No. The output uses plain types plus the json tag with the original key name. If a field can be missing or null, switch it to *T and add ,omitempty to the tag yourself.
Is the pasted JSON sent to a server?
No. The conversion happens in JavaScript inside your tab, so you can paste payloads from internal environments without anything leaving the machine.

Related Tools