JSONGenerator
GeneratorSchemaConvertersExamplesDocs

JSONGenerator

Free online tools for generating random JSON data and JSON Schemas.

Quick Links

  • JSON Generator
  • JSON Schema Converter
  • Examples
  • Docs
  • Blog
  • About
  • Contact
  • Privacy Policy

Converters

  • JSON to YAML
  • YAML to JSON
  • XML to JSON
  • JSON to XML
  • JSON to TOML
  • TOML to JSON
  • JSON to CSV
  • CSV to JSON
  • JSON to Excel
  • Excel to JSON
  • JSON to HTML table
  • JSON to TypeScript
  • JSON to C#
  • JSON to Go
  • JSON to Java
  • JSON to SQL

Support

Having issues? Contact us.

© 2026 JSON Generator. All rights reserved.

JSON to Go Struct Converter

Paste JSON and get Go structs with json tags as you type.

JSON Input

Paste JSON, upload a .json file or drop one here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
  "user_id": 48213,
  "username": "ada.lovelace",
  "email": "ada@example.com",
  "is_active": true,
  "balance": 1042.75,
  "created_at": "2024-03-18T09:30:00Z",
  "nickname": null,
  "roles": ["admin", "editor"],
  "address": {
    "street": "12 Analytical Way",
    "city": "London",
    "postal_code": "N1 9GU"
  },
  "orders": [
    { "id": 1, "total": 59.9, "coupon": "SPRING", "shipped_at": null },
    { "id": 2, "total": 120 }
  ]
}

Go Output

Updates as you type. Copy it or download models.go.

1

Converting…

Convert JSON to a Go struct online

This free JSON to Go struct converter reads a sample JSON document and writes the Go types that match it: exported fields, json tags, nested structs and slices. Paste an API response, a webhook payload or a config file and the code appears as you type, ready to paste into your package. Nothing is uploaded, because the structs are generated in your browser.

Writing these types by hand is slow and easy to get wrong, especially for payloads with dozens of fields or several levels of nesting. Generating them from a real sample gives you a correct starting point that you can then rename, trim and document. If you are looking for a quick way to go from JSON to Golang types without installing a CLI, this is it.

How to convert JSON to Go

  1. Paste your JSON into the JSON Input editor, or click the upload button to open a .json file. You can also drag a file onto the editor.
  2. The Go Output updates as you type. If the JSON is invalid, the status bar shows the parser's error so you can fix it.
  3. Set the Struct name for the root type and the Package name, and tick omitempty on all fields if you want it on every tag.
  4. Click Copy to put the code on your clipboard, or Download to save it as models.go.

JSON to Go struct example

Here is a small user record and the Go it produces. Field names are capitalized so they are exported, each one keeps its original key in a tag, and the nested address object and the orders array each get their own struct.

JSON input
{
  "user_id": 48213,
  "username": "ada",
  "balance": 1042.75,
  "created_at": "2024-03-18T09:30:00Z",
  "roles": ["admin", "editor"],
  "address": {
    "city": "London",
    "postal_code": "N1 9GU"
  },
  "orders": [
    { "id": 1, "total": 59.9, "coupon": "SPRING" },
    { "id": 2, "total": 120 }
  ]
}
Go output
package main

import "time"

type Root struct {
	UserID    int64     `json:"user_id"`
	Username  string    `json:"username"`
	Balance   float64   `json:"balance"`
	CreatedAt time.Time `json:"created_at"`
	Roles     []string  `json:"roles"`
	Address   Address   `json:"address"`
	Orders    []Order   `json:"orders"`
}

type Address struct {
	City       string `json:"city"`
	PostalCode string `json:"postal_code"`
}

type Order struct {
	ID     int64   `json:"id"`
	Total  float64 `json:"total"`
	Coupon *string `json:"coupon,omitempty"`
}

To decode JSON into these types, pass a pointer to json.Unmarshal. The generated structs work with the standard library as they are.

Decoding with encoding/json
package main

import (
	"encoding/json"
	"fmt"
	"log"
	"os"
)

func main() {
	data, err := os.ReadFile("user.json")
	if err != nil {
		log.Fatal(err)
	}

	var user Root
	if err := json.Unmarshal(data, &user); err != nil {
		log.Fatal(err)
	}

	fmt.Println(user.Username, len(user.Orders))
}

How JSON types map to Go

JSON values and the Go types generated for them
JSONGo typeNotes
objectstructEach nested object gets its own named struct.
array[]TAn empty array has no element type, so it becomes []interface{}.
stringstringISO 8601 date-times become time.Time.
whole numberint64Fits any integer up to 64 bits.
number with a fractionfloat64A field that mixes both, like 1.5 and 2, becomes float64.
true / falseboolDirect mapping.
nullinterface{}Or a pointer such as *string when other objects show the real type.

Exported fields and json tags

The encoding/json package only reads and writes exported fields, so every field name must start with an upper-case letter. The converter turns keys into idiomatic Go names: user_id becomes UserID, weird-key becomes WeirdKey and a key such as 1st becomes The1St. The tag, for example `json:"user_id"`, records the real key. It is what makes decoding and encoding work, since the Go name no longer matches the JSON key.

omitempty

Adding ,omitempty to a tag makes json.Marshal skip the field when it holds a zero value: 0, false, an empty string, a nil pointer or an empty slice. The converter adds it by itself to fields that are missing from some objects in your sample, like coupon in the example. The omitempty on all fields checkbox adds it to every tag, which is handy for request bodies where unset fields should not be sent. Keep in mind that omitempty has no effect on struct values such as time.Time; Go 1.24 added an omitzero option for that.

Nullable values and pointers

Go values cannot be nil unless they are pointers, slices, maps or interfaces. When a field is null in one array element and a string in another, the output uses *string, so you can tell a missing value from an empty one. A field that is null in your only sample has no known type and becomes interface{}; replace it with the right type once you know it.

Numbers and dates

The types come from your sample, so use one that is representative. If a price is 10 in the sample but 10.5 in production, an int64 field fails to decode the second value, so include examples of both in an array and the converter picks float64. Date-times in RFC 3339 form decode into time.Time directly; plain dates such as 2024-03-18 stay strings and need parsing with time.Parse.

Why convert JSON to Go structs?

  • Consuming third-party APIs: Paste a sample response and get typed models for your HTTP client instead of map[string]interface{}.
  • Webhook and event payloads: Decode Stripe-style or GitHub-style events into structs and let the compiler catch typos in field names.
  • Config and fixture files: Load JSON config or test fixtures into typed values with a single json.Unmarshal call.
  • Prototyping a service: Start from the JSON your frontend sends and refine the generated structs into your API models.

Working in more than one language? The same sample also converts to a JSON to TypeScript interface, a C# class or a Java class. Need sample data to try the converter on? Create some with the JSON Generator, or describe a document's shape with the JSON Schema generator. For wire formats compared, see Protobuf vs JSON.

Frequently Asked Questions

How do I convert JSON to a Go struct?

Paste your JSON into the JSON Input editor, or upload a .json file. The Go structs appear in the output editor as you type. Copy them, or click Download to save models.go, then decode your data with json.Unmarshal.

Why are the struct fields capitalized?

Go only exports identifiers that start with an upper-case letter, and encoding/json ignores unexported fields. The converter capitalizes each name (user_id becomes UserID) and keeps the original key in the json tag so the field still matches your JSON.

When does the output use int64, float64 or a pointer?

Whole numbers become int64 and numbers with a fraction become float64. A field that is null in some objects of an array, such as a note that is null in one order and a string in another, becomes a pointer like *string. A null with no other example becomes interface{}.

What does omitempty do?

The omitempty tag option tells json.Marshal to leave out a field when it holds a zero value such as 0, false, an empty string, a nil pointer or an empty slice. Tick omitempty on all fields to add it to every tag. Fields that are missing from some objects in your sample already get it automatically.

Are dates converted to time.Time?

Strings in ISO 8601 date-time form, such as 2024-03-18T09:30:00Z, become time.Time and the output adds the time import. Date-only strings like 2024-03-18 stay string, because they are not valid RFC 3339 timestamps for time.Time.

Is my JSON uploaded to a server?

No. The structs are generated entirely in your browser, so your JSON never leaves your device. That makes it safe to use with real API responses that contain private data.

Related converters

  • JSON to TypeScript ConverterGenerate TypeScript interfaces or types from a JSON sample.
  • JSON to C# Class ConverterGenerate C# classes with properties for System.Text.Json or Newtonsoft.Json from JSON.
  • JSON to Java Class ConverterGenerate Java POJO classes with getters and setters from JSON.
  • JSON to SQL ConverterGenerate a CREATE TABLE statement and INSERT rows from a JSON array.
  • JSON to YAML ConverterConvert JSON to clean, readable YAML for config files, Kubernetes and CI pipelines.
  • YAML to JSON ConverterConvert YAML, including anchors and multi-document files, to formatted JSON.

See all JSON converters