JSON Schema to Go: Structs, Pointers and Tags From One Schema
If you already describe your API or config with a JSON Schema, there is no reason to type the matching Go structs by hand. Paste the schema and you get structs that encoding/json can read straight away. To start from a sample document instead of a schema, use JSON to Go; for Rust there is JSON Schema to Rust, and JSON Schema Validator checks a document against the schema itself.
Paste or upload your JSON Schema
Drop the schema into the left editor, or upload a .json file. Click Sample if you just want to see what comes out. Set the Struct Name for the top-level type.
Read the generated structs
Each object with properties becomes its own struct, $ref targets become named types, and string enums become a named string type with one constant per value. Anything that could not be turned into an exact Go type is listed in a Note comment at the top.
Pick the tags you want
The json button adds encoding/json tags (with omitempty on optional fields) and the validate button adds go-playground/validator tags for lengths, ranges, formats like email and enum values. Turn either off if you do not need it.
Copy or download the .go file
Copy the code or download it as a .go file and drop it into your package. It is plain Go: only encoding/json is imported, and only when a field needs json.Number.
Frequently Asked Questions
Which JSON Schema keywords does it read?
type (including lists like ["string", "null"]), properties, required, items, enum, const, default, format, minimum and maximum (and the exclusive forms), minLength, maxLength, minItems, maxItems, additionalProperties with a schema, allOf (merged into one struct) and $ref pointing inside the same file, such as #/$defs/Name, #/definitions/Name or # for the root. A oneOf or anyOf that is one type plus null becomes a pointer; anything with several real shapes becomes interface{} and a Note comment says so. References to other files are not followed.
How do required and optional fields come out in Go?
A property listed in required becomes a plain field, like ID int64. A property that is not required, or whose type allows null, becomes a pointer such as *string or *int with omitempty in its json tag, so you can tell a missing value from an empty string or 0. Slices, maps and interface{} fields are never pointers because they can already be nil. A field that refers back to its own struct is always a pointer, since Go does not allow a struct to contain itself by value.
Which integer type does a field get?
int64 by default, so a long ID like 8901240544102066246 fits. A format such as int32 or uint64 is used as written. When both a minimum and a maximum are given (or an enum or const) and they fit in 32 bits, the field is int. A maximum above the int64 range with a minimum of 0 or more gives uint64. The limits are read from the exact digits in your schema, so 18446744073709551615 is not rounded on the way; anything bigger than 64 bits becomes json.Number, which keeps the digits as text.
What do the validate tags check?
They are written for github.com/go-playground/validator/v10: min and max for string lengths, number ranges and array sizes, gt and lt for exclusive limits, email, url, uuid, ipv4, ipv6 and hostname for matching formats, and oneof for enums with simple values. Optional fields start with omitempty so a missing value passes. Required fields do not get the required tag, because validator would then reject a legitimate 0, false or empty string. A pattern is copied into a comment instead of a tag, since validator has no regular-expression check.
What happens to property names that are not valid in Go?
Field names become exported PascalCase with Go initialisms, so user_id becomes UserID. Names starting with a digit or a non-Latin letter get an X prefix (2nd becomes X2nd), and names that clash after cleaning get 2, 3 and so on. The json tag always keeps the original key. encoding/json cannot use a key that is empty or contains a comma, quote, backslash or backtick, so such a field is marked json:"-" and listed in a Note.
Is my schema uploaded anywhere?
No. The conversion runs in your browser, nothing is sent to a server, and nothing is kept: a reload starts with an empty editor.
External Resources & Documentation
Complete JSON Schema specification and documentation
Go struct validation library using tags compatible with JSON Schema constraints
Comprehensive guide to JSON Schema concepts and usage
JSON Schema validator for Go supporting all drafts
Official Go JSON encoding and decoding documentation
List of JSON Schema validators and tools for various languages
Official guide to working with JSON in Go
Another popular JSON Schema validation library for Go
Related Tools
JSON to Go
Convert JSON data to Go structs with json tags
YAML to Go
Convert YAML configuration to Go structs with yaml tags
TOML to Go
Convert TOML configuration to Go config structs
XML to Go
Convert XML data to Go structs with xml tags
CSV to Go
Convert CSV data to Go structs with field mapping
TypeScript to Go
Convert TypeScript interfaces and types to Go structs