JSON to Go Struct

Paste JSON and generate clean, ready-to-paste Go structs with presets, nullable options, root arrays, and optional time-aware fields.

Quickly apply sensible tag and nullability defaults.

Adds a second tag beside json.

Used for whole numbers in the sample JSON.

Used for decimal numbers in the sample JSON.

Choose how nullable or missing collection fields should be emitted.

Input JSON

Generated Go

Your generated Go structs will appear here.

How to use this tool

  1. Paste a JSON object or JSON array into the input box.
  2. Set the root type name, preset, and optionally include a package declaration.
  3. Choose field export, tag, pointer, time detection, collection, and numeric type options.
  4. Copy the generated Go structs, imports, or slice type into your project.
Mixed-type arrays and heavily inconsistent samples still fall back to interface{} when a safe concrete type cannot be inferred.

What it handles

  • ✅ Nested objects
  • ✅ Root arrays and arrays of objects
  • ✅ Configurable int/int64 and float64/float32
  • time.Time detection with automatic import "time"
  • ✅ Package declarations, JSON tags, extra tags, and presets
  • ✅ Optional pointer fields, nullable slice strategy, and copy-ready output

FAQ

Does this tool send my JSON to a server?

No. Everything runs in your browser, so your JSON stays on your device.

Why do some fields become interface{}?

That happens when the sample data mixes incompatible types or when the input is too ambiguous to infer a safe Go type.

Does it support root JSON arrays?

Yes. If you paste a root array, the tool generates a named slice type like type AutoGenerated []AutoGeneratedItem.

Can I generate package lines and extra struct tags?

Yes. You can prepend a package declaration and add a second struct tag such as bson, yaml, mapstructure, or form.

Can it generate time.Time and nullable collection types?

Yes. ISO-8601 datetime strings can become time.Time, and nullable arrays can stay as []T or switch to *[]T depending on the selected strategy.