I Help You

JSON → Go Struct

Convert JSON to a Go struct with json/yaml/db/xml struct tags — PascalCase fields, acronym fixes (ID, URL, API), nested structs, omitempty and pointer options. Free, and it runs entirely in your browser — nothing you enter is uploaded.

How to use the JSON → Go Struct

1. Paste a JSON object (or array — the first element is used) into the input panel.

2. Set the root struct name, choose which struct tags to include, and toggle omitempty / pointer options.

3. The Go struct definition is generated instantly — copy and paste into your Go file.

Tip: nested JSON objects become nested Go struct types. Arrays become slices.

What is it?

Go structs are the primary way to map JSON to typed Go values. The encoding/json package uses struct tags (json:"field_name") to control how struct fields are serialised and deserialised. Writing these manually is tedious and error-prone — especially for deeply nested API responses.

This tool generates idiomatic Go structs from any JSON sample. Field names are converted from snake_case or camelCase JSON keys to PascalCase Go identifiers. Common acronyms are properly uppercased (e.g. userId → UserID, apiUrl → APIURL). Nested objects become named sub-structs.

You can also generate tags for YAML, DB (sqlx), XML, and form parsing simultaneously. The omitempty option skips fields with zero values during marshalling — useful for partial-update APIs.

Example

JSON
{"id": 1, "user_name": "alice", "email": "[email protected]"}
↓
Go Struct
type MyStruct struct {
	ID       int    `json:"id"`
	UserName string `json:"user_name"`
	Email    string `json:"email"`
}

Field name conversion: user_name → UserName, id → ID (acronym fix). Add yaml/db tags for multi-format support.

Benefits

Generate accurate code from your actual data

TypeScript interfaces, Python dataclasses, and OpenAI function schemas are generated directly from your real JSON — accurate field names, correct types, no guesswork.

Control LLM API costs before you scale

Token counts and per-call cost estimates for GPT-4o, Claude 3.5, and Gemini let you optimise prompt size and model choice before a feature goes to production.

Ready-to-run code and configs, not boilerplate

Every tool produces output you can paste directly into your project — API request code, prompt templates, chunk configurations — adapt rather than write from scratch.

Purpose-built for AI engineering workflows

From RAG chunking strategy to prompt template selection to function calling schema design — tools built for the specific problems AI engineers encounter daily.

Frequently asked questions

Why does 'id' become 'ID' instead of 'Id'?

Go style (Effective Go) requires common initialisms to be fully uppercased — ID, URL, HTTP, API, etc. This tool applies these corrections automatically so your generated code passes golint/staticcheck.

What does omitempty do?

The omitempty option adds ,omitempty to every json tag. This tells encoding/json to skip the field when marshalling if the value is the zero value (0 for int, "" for string, nil for pointers). Useful for PATCH APIs where you only send changed fields.

How do I use the db tag with sqlx?

The db tag is used by the sqlx package (and pgx/squirrel) to map struct fields to SQL column names. Select the db tag option to generate db:"column_name" tags alongside json tags.

My JSON has null values — what type is generated?

Null JSON values map to interface{} by default. Enable the "Use pointers" option to generate pointer types (*string, *int) instead, which can explicitly represent the absence of a value.

How do I unmarshal a JSON array into Go?

If your JSON is an array, the tool uses the first element to infer types and generates the element struct. Unmarshal with: var items []MyStruct; json.Unmarshal(data, &items)