chain
go
JSON to Go error
⌃⏎ run · clear · / focus input
// about this tool

JSON to Go Online

Updated 2026-08-04

// how to use

  1. 1 Paste your JSON — an array of objects lets the optional fields be detected.
  2. 2 Set the root name; nested objects become their own structs, named from their key.
  3. 3 Copy the structs into your package; the output is already gofmt-aligned.

// examples

A flat object
Input
{"user_id": 7, "name": "Ada"}
Output
type Root struct with UserID int `json:"user_id"` and Name string `json:"name"`
An optional field
Input
[{"id": 1}, {"id": 2, "note": "rush"}]
Output
Note becomes *string with `json:"note,omitempty"`
An id field
Input
{"api_url": "https://example.com"}
Output
APIURL, not ApiUrl — Go initialisms are applied

// common uses

Turning an API response into structs without hand-writing tags Getting the json tags right for snake_case payloads Working out which fields a third-party API actually always returns Scaffolding types for a new service quickly

// faq

Why are optional fields pointers?
Because a pointer is the only way Go distinguishes "the key was absent" from "the key was the zero value". Without it, a missing `count` and a `count` of 0 both unmarshal to 0, and you cannot tell which happened. Fields present in every record are plain values.
Why is it APIURL rather than ApiUrl?
Go's own naming convention keeps initialisms uppercase — the standard library and golint both expect ID, URL, API, HTTP and so on. Generated code that gets this wrong is the first thing a reviewer comments on.
Do I need to run gofmt on the output?
No. Both the type and the struct-tag columns are already aligned the way gofmt would align them, so pasting it in will not produce a diff.
What is omitempty doing?
It tells encoding/json to leave the key out when marshalling if the value is empty, which keeps round-tripped JSON close to what you started with. It is added only to fields detected as optional.
Is my JSON uploaded?
No. Everything runs in your browser, so the JSON never leaves your machine.

Use this via API

Get a free API key →
curl -X POST https://thesnaptools.com/api/v1/tools/json-to-go \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"json":"{\"user_id\": 7, \"name\": \"Ada\"}"}'
Esc
↑↓ navigate open Esc close