JSON to Go Struct
Generate an exported Go struct from a JSON example, with exact JSON tags, nested fields and conservative types for uncertain values.
This tool processes its input contents in your browser instead of sending them to a processing service. Page, asset and fixed usage-measurement requests are described on the Privacy page.
Infer an exported Go struct template from one JSON object, with json.Number fields, nested structs and tags that retain supported property names.
How to use it
- 1Paste a JSON object or open a local JSON example.
- 2Choose an exported root type name and generate the template.
- 3Review uncertain fields, then copy or download the Go file.
Example
- Input
- {"order_id":9007199254740993,"active":true}
- Output
- type Order struct { OrderID json.Number "json:\"order_id\"" Active bool "json:\"active\"" }
The complete Go file uses package models and imports encoding/json. json.Number retains a numeric token during decoding.
What happens to your data
The example and generated Go model remain in this browser. Optional usage counts exclude property names, values and generated code.
Last updated November 2026
Turn one JSON example into a Go type template you can review and adapt. Paste a top-level object, choose the exported root type name and generate a complete .go file. The converter uses exported field names, keeps the original JSON names in encoding/json tags and builds inline structs for nested objects.
How it works
The generator examines every value in the bounded example. Strings become string, booleans become bool and numeric values become json.Number. Using json.Number avoids guessing an integer width or converting a long numeric ID into a floating-point value. Arrays are inspected together. Object items contribute a union of their fields, while incompatible mixed item types and empty arrays use any where the sample provides too little information.
A field that appears in only some observed array objects is marked optional with omitempty. Nullable scalar or object values use pointers when the remaining values share a type. Go pointers and omitempty cannot preserve every difference between missing and explicitly null values. Review those choices before using the types as an API contract. The generator does not infer date formats, validation rules, required fields outside the observed examples or complete sets of future values.
Field names are made from exported ASCII words, with common initialisms such as ID and URL. Collisions receive a numeric suffix. Tags preserve valid original property names. If encoding/json cannot represent a property name in a struct tag, generation stops with a map/custom-unmarshaler suggestion instead of silently changing that name. The output uses package models and Go 1.18+ any where needed. Use Decoder.UseNumber when decoding numeric values through any fields.
Input is limited to 128 KiB, 5,000 JSON values, 24 nested levels and 1,000 generated fields. Duplicate property names are rejected. Download the template and test it against representative payloads, including optional and null fields, before integrating it into your application.
Worked example: Keep a numeric ID in its numeric form
- Input
- {"order_id":9007199254740993,"active":true}
- Result
- type Order struct { OrderID json.Number "json:\"order_id\"" Active bool "json:\"active\"" }
The complete Go file uses package models and imports encoding/json. json.Number retains a numeric token during decoding.
Common use cases
- Start an encoding/json model for a documented API response.
- Keep long numeric IDs as json.Number while reviewing a payload.
- Find mixed or empty array shapes that need a deliberate Go type.
- Generate a nested template without giving a converter access to the API itself.
Frequently asked questions
Why do numeric fields use json.Number?+
A single example cannot establish an appropriate Go integer width or decimal policy. json.Number retains the numeric token and lets your application deliberately parse or validate it.
Does this generate a complete API schema?+
It infers a template from the supplied example. It cannot prove which future properties are required, how dates should be parsed or what values the server may send later.
What happens to nulls and missing fields?+
Known nullable scalar and object types use pointers. Missing fields across observed object items can gain omitempty. Missing and explicitly null values can still become indistinguishable, so check your application’s required semantics.
Can it handle property names with punctuation?+
It retains names supported by encoding/json struct tags and creates a separate exported Go field name. Names outside the tag grammar cause a clear error so you can use a map or custom decoder.
Does it run or upload the generated Go code?+
It generates text in your browser. You can copy or download the .go file and review it in your own development environment.
Related tools
JSON Formatter & Validator
Format, validate, and minify JSON with exact line errors, a searchable tree, and private processing.
JSON to TypeScript
Generate TypeScript interfaces from a JSON sample.
JSON Schema Generator
Generate a draft 2020-12 schema from JSON examples and check their observed types locally.
JSON Schema Example Generator
Create one deterministic JSON example from a documented JSON Schema subset, with clear errors for unsupported constraints and no remote references.