Output will appear here
Output will appear here
Paste JSON and get Go structs ready for json.Unmarshal. Every field has a json:"..." tag with the original key, and names follow Go style, so avatar_url becomes AvatarURL. Keys missing from some objects become pointers with omitempty. RFC 3339 timestamps become time.Time, and a string that repeats a few values gets its own named type with a const block.
By Ankit Aglawe · Updated · Runs entirely in your browser
Initialisms are capitalised the way golint wants: NodeID, HTMLURL, SpdxID. owner and license become their own structs. description is null in this sample, so it is interface{}; paste a repo that has a description and it becomes *string.
{
"id": 1296269,
"node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5",
"name": "Hello-World",
"full_name": "octocat/Hello-World",
"private": false,
"owner": { "login": "octocat", "id": 1, "avatar_url": "https://github.com/images/error/octocat_happy.gif", "site_admin": false },
"html_url": "https://github.com/octocat/Hello-World",
"description": null,
"fork": false,
"language": "Go",
"stargazers_count": 80,
"topics": ["octocat", "atom", "electron", "api"],
"pushed_at": "2011-01-26T19:06:43Z",
"license": { "key": "mit", "name": "MIT License", "spdx_id": "MIT" }
}package main
import "time"
type Owner struct {
Login string `json:"login"`
ID int `json:"id"`
AvatarURL string `json:"avatar_url"`
SiteAdmin bool `json:"site_admin"`
}
type License struct {
Key string `json:"key"`
Name string `json:"name"`
SpdxID string `json:"spdx_id"`
}
type Root struct {
ID int `json:"id"`
NodeID string `json:"node_id"`
Name string `json:"name"`
FullName string `json:"full_name"`
Private bool `json:"private"`
Owner Owner `json:"owner"`
HTMLURL string `json:"html_url"`
Description interface{} `json:"description"`
Fork bool `json:"fork"`
Language string `json:"language"`
StargazersCount int `json:"stargazers_count"`
Topics []string `json:"topics"`
PushedAt time.Time `json:"pushed_at"`
License License `json:"license"`
}level becomes type Level string with LevelInfo, LevelWarn and LevelError constants. duration_ms mixes 30000 with 1240.5, so it is float64. port, duration_ms and trace_id are not on every line, so they are pointers with omitempty. The slice type RootArray is added for the top-level array.
[
{ "ts": "2026-10-28T10:00:01Z", "level": "info", "msg": "server started", "port": 8080 },
{ "ts": "2026-10-28T10:00:07Z", "level": "warn", "msg": "slow query", "duration_ms": 1240.5 },
{ "ts": "2026-10-28T10:01:12Z", "level": "error", "msg": "upstream timeout", "duration_ms": 30000, "trace_id": "4bf92f3577b34da6" },
{ "ts": "2026-10-28T10:02:00Z", "level": "info", "msg": "request", "duration_ms": 12.25 },
{ "ts": "2026-10-28T10:02:05Z", "level": "warn", "msg": "retrying", "duration_ms": 88.0 },
{ "ts": "2026-10-28T10:02:09Z", "level": "info", "msg": "request", "duration_ms": 9.75 }
]package main
import "time"
type Level string
const (
LevelInfo Level = "info"
LevelWarn Level = "warn"
LevelError Level = "error"
)
type Root struct {
Ts time.Time `json:"ts"`
Level Level `json:"level"`
Msg string `json:"msg"`
Port *int `json:"port,omitempty"`
DurationMs *float64 `json:"duration_ms,omitempty"`
TraceID *string `json:"trace_id,omitempty"`
}
type RootArray []RootEvery code generator on this site is run on the same awkward input: a 64-bit id, a float written as 1.0, a null, a date string, a reserved word as a key, an empty array, a nested array and an array of objects whose keys differ. This is the exact output for Go Struct, generated when the page was built.
{
"id": 9007199254740993,
"price": 19.99,
"ratio": 1.0,
"deleted_at": null,
"created_at": "2024-01-15T10:30:00Z",
"class": "premium",
"tags": [],
"matrix": [[1, 2], [3, 4.5]],
"items": [{ "sku": "A1", "qty": 1 }, { "sku": "B2", "qty": 2, "note": "gift" }]
}package main
import "time"
type Item struct {
Sku string `json:"sku"`
Qty int `json:"qty"`
Note *string `json:"note,omitempty"`
}
type Root struct {
ID int `json:"id"`
Price float64 `json:"price"`
Ratio int `json:"ratio"`
DeletedAt interface{} `json:"deleted_at"`
CreatedAt time.Time `json:"created_at"`
Class string `json:"class"`
Tags []interface{} `json:"tags"`
Matrix [][]float64 `json:"matrix"`
Items []Item `json:"items"`
}A key absent from some objects becomes a pointer such as *string with ,omitempty, so you can tell "not sent" (nil) from the zero value, and marshalling leaves it out again. A key that holds null and a value also becomes a pointer. Slices, maps and interface{} are already nil-able and are never wrapped.
deleted_at has no observed type, so it is interface{}. That decodes anything without error, but you will need a type assertion to use it. Replace it with *time.Time or whatever the field really holds.
Whole numbers become int, which is 64 bits on amd64 and arm64. encoding/json decodes from the raw text, so the 64-bit id keeps all its digits. One catch: 1.0 is read as a whole number here and typed int, but Go refuses to unmarshal 1.0 into an int. If a field can hold 1.0, make it float64.
Go field names are exported and PascalCase, so type, class and func turn into Type, Class and Func and never clash with keywords. user-name becomes UserName and 2fa becomes Field2fa. The tag always carries the exact JSON key.
2024-01-15T10:30:00Z becomes time.Time and import "time" is added. time.Time only unmarshals RFC 3339, which needs a T and a zone (Z or +02:00). Strings like 2024-01-15 10:30:00, or ones without a zone, are left as string for that reason; parse them yourself with time.Parse and the right layout.
An empty array is []interface{}. [[1, 2], [3, 4.5]] is [][]float64. Go has no union types, so an array that mixes strings, numbers and nulls is []interface{} too.
| JSON value | Go type | Notes |
|---|---|---|
| string | string | Named string type + consts for a repeated set |
| RFC 3339 timestamp | time.Time | |
| integer | int | 64-bit on 64-bit platforms |
| float | float64 | |
| true / false | bool | |
| null alongside a value | *T | |
| key missing in some objects | *T + omitempty | |
| object | type Name struct | Named after its key |
| array | []T | []interface{} when empty or mixed |
| only null | interface{} |
Enter a JSON object or array in the input editor. The converter supports deeply nested structures, arrays of objects, and mixed-type fields.
The output pane shows Go structs with exported fields, json struct tags, and inferred types like string, int, float64, bool and time.Time.
Copy the structs to your clipboard or download a .go file you can add directly to your Go package.
Paste the JSON and copy the structs into your package, changing package main if needed. Then var r Root; err := json.Unmarshal(data, &r) fills it.
Yes. Every fixture in the project test suite is compiled with the Go toolchain when one is available, so output with a duplicate or undefined type fails the check.
A pointer means the key was missing from some objects or held null. With a pointer, nil means "not present", which a plain int or string cannot express because their zero values look like real data.
Keys are split on underscores, dashes and camelCase, then PascalCased, and common initialisms are uppercased: user_id is UserID, html_url is HTMLURL. The json tag keeps the original key.
Go has no enum keyword, so a field with a small repeated set of values gets type Status string and a const block of typed values. encoding/json does not check that a decoded value is one of them.
No. The structs are generated by JavaScript in your browser and the input never leaves your machine.
Need several formats at once? Convert All shows every output from one paste. Or browse all JSON converters.