Go Struct to JSON Schema Generator

Need JSON to Go?
JSON → Go Structs

Go code Input

Loading editor…

JSON Schema Output

Settings

Choose which struct should be treated as the JSON Schema root.

Parsing runs entirely in your browser. Your source never leaves the page.

Paste your Go structs to produce JSON Schema instantly.

Supports struct tags, slices, maps, embedded structs, and pointer fields.

How to convert Go structs to JSON Schema – step-by-step guide

This online Go struct to JSON Schema converter helps you generate JSON Schema from real models (DTOs, structs, and classes) so you can validate payloads, share contracts, and generate mock JSON.

  1. Step 1 – Paste your Go source

    • Paste the models you want to document into the left editor.
    • Include referenced types in the same snippet so the schema can generate definitions.
    • Use the Sample button to load an example and see the expected input format.
  2. Step 2 – Select the Root struct (if needed)

    • If multiple definitions are detected, choose the root that matches your API payload.
    • The output schema is built around the selected root and may include additional definitions for referenced types.
  3. Step 3 – Review the JSON Schema output

    • Check types, required vs. optional fields, and nested object/array structures.
    • Look for definitions and $ref when your models reference other models.
    • Copy or download the schema for validation, documentation, or schema-first development.
  4. Step 4 – Validate or generate mock JSON

    • Click Generate Mock Data to open the mock generator with your schema preloaded.
    • Validate real payloads against your schema to catch breaking changes early.
    • If you rely on advanced schema composition (for example anyOf/oneOf/allOf), verify the result with a full validator like Ajv.

Schema keyword support note

Generated schemas can include $ref and may be edited to include anyOf, oneOf, or allOf. For complex schemas, use a full JSON Schema validator and dereference before mock generation if needed.

Related JSON Schema & code generation tools

Use these tools to validate schemas, generate mock payloads, format JSON examples, and keep code and contracts in sync.

Frequently Asked Questions

What Go syntax is supported?

The parser reads type declarations for structs, including exported/unexported fields, slices, arrays, maps, pointers, embedded structs, and tags such as `json:"name,omitempty"`. Fields tagged with `json:"-"` are skipped automatically.

How are Go types mapped to JSON Schema?

Primitive types (string, bool, int/uint sizes, floats, time.Time, etc.) are mapped directly to JSON Schema primitives. Slices and arrays become schema arrays, maps become objects with additionalProperties, and pointer types are treated as optional fields.

Does it run locally?

Yes. Conversion happens entirely inside your browser. Paste private structs or DTOs without leaving your machine. The tool infers schema without calling any backend services.

How do I generate mock JSON?

After you generate the schema, click "Generate Mock Data" to open the Mock Generator with the schema preloaded. Configure locales, array counts, and optional fields to create sample payloads instantly.

Convert Go Structs to JSON Schema Online | JSONSwiss