Skip to content
86% off$349 $48.86code BF2026

Guides

JSON to Go Struct Generator Offline: quicktype Alternatives

Generate Go structs, Dart classes or C++ types from JSON offline: json-to-go, the quicktype CLI, hand-written code or an LLM, and how to check the result.

GuideUpdated 6 min read

On this page

You have a JSON payload or a schema and need Go structs, a Dart class or C++ types, without pasting your data into a website. People on r/golang recommended json-to-go more often than "ask an LLM". One poster on r/cpp_questions called quicktype "completely broken and unmaintained with more than 500 issues on github" once a schema gets convoluted. This page covers what to use, what each route cannot do, and how to check the result.

Why generators struggle with real schemas

A sample payload is easy: keys become fields, values suggest types. Trouble starts when the input says less than you need.

  • One sample hides optional fields. A field that is always present in your sample may be missing elsewhere, and a null tells the tool nothing about the real type.
  • Alternatives have no natural Go type. Go has no built-in "one of these shapes" type, so for oneOf and anyOf every tool has to guess, usually with a loose type.
  • Deep $ref chains and allOf merging produce odd or duplicated type names.
  • Decisions only you can make: nullability, ID size, and timestamp format.

The quicktype complaint is about output quality on convoluted schemas. We have not tested it, and we have not verified the issue count. "Unmaintained" looks too strong: the project's release history shows recent releases (v24.0.0 about four months before we checked, and v26.0.0 since). Run your own schema through it and read the result.

Which route fits what you have

You haveTryNote
One sample payload, Go targetWrite it by hand, or json-to-goNullability, ID size and timestamps matter more than the typing
Several samples of one payloadquicktype CLIMore samples reveal optional fields
A plain JSON Schemaquicktype CLI with --src-lang schemaquicktype reads schema as well as sample JSON
A schema with oneOf, anyOf, allOf or deep $refLLM or generator for a draft, then hand editsEvery tool guesses here
Dart targetHand-written class, or a package such as freezedCheck quicktype --help for Dart first
C++ targetnlohmann/json macro by hand, or quicktypequicktype lists C++ among its targets

Go: write the struct from a sample payload

json-to-go got the most recommendations in the r/golang thread (April 2025). We have not tested it for this page, so check the project's own page for how it runs and whether you can use it fully offline. Writing the struct yourself is always offline. For this payload:

json
{
  "id": 9007199254740993,
  "name": "Widget",
  "price": 9.5,
  "tags": ["a", "b"],
  "discount": null,
  "created_at": "2026-11-01T10:00:00Z"
}

a reasonable struct is:

go
type Product struct {
	ID        int64     `json:"id"`
	Name      string    `json:"name"`
	Price     float64   `json:"price"`
	Tags      []string  `json:"tags"`
	Discount  *float64  `json:"discount"`
	CreatedAt time.Time `json:"created_at"`
}

Three decisions a generator can only guess at:

  • Nullable fields: use a pointer (*float64) so you can tell null from 0.
  • Large IDs: use int64 (or string), not float64, which cannot hold every integer above 2^53 exactly.
  • Timestamps: time.Time decodes RFC 3339 strings like the one above. Other formats need a custom type.

Offline generation with the quicktype CLI

quicktype reads sample JSON, JSON Schema or GraphQL and generates typed models for many languages, including Go and C++. The project says its web app works offline and needs no installation. The command-line tool needs Node.js 20 or later.

bash
npm install -g quicktype
quicktype --src-lang json --lang go --package models -o product.go sample.json

The first line installs the quicktype command globally. The second writes product.go from sample.json. To remove it later, run npm uninstall -g quicktype.

For a schema, change the source language:

bash
quicktype --src-lang schema --lang go --package models -o types.go schema.json

Run quicktype --help to see the target languages and per-language options for the version you installed.

Dart: write the model or use a package

The 2023 r/FlutterDev thread asked for a tool that turns JSON into Dart models. For a small model, a hand-written class is short:

dart
class Product {
  final int id;
  final String name;
  final double? discount;

  Product({required this.id, required this.name, this.discount});

  factory Product.fromJson(Map<String, dynamic> json) => Product(
        id: json['id'] as int,
        name: json['name'] as String,
        discount: (json['discount'] as num?)?.toDouble(),
      );

  Map<String, dynamic> toJson() => {
        'id': id,
        'name': name,
        'discount': discount,
      };
}

Cast through num? for decimals: JSON written as 9 arrives as an int, and a direct as double? cast would throw.

For many models, a code-generation package is the usual next step. freezed is one; we have not reviewed it, so read its package page for current behavior. You can also check whether your quicktype version lists Dart in quicktype --help and try it on a real payload.

C++: nlohmann/json for small models

For a few types, a struct plus one macro from the nlohmann/json library is the usual hand-written route:

cpp
#include <nlohmann/json.hpp>

struct Item {
    std::string name;
    int qty;
};
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Item, name, qty)

This lets you convert Item to and from JSON. Optional and nullable fields need extra handling, and a schema with alternatives usually means std::variant, which you write yourself. quicktype lists C++ as a target, so it is worth one try on your schema.

Complex schemas: ask an LLM for a draft

"Ask an LLM" was the other common answer in the r/golang thread. It is a reasonable first pass where generators struggle. Give it:

  • the schema or sample,
  • the target language and package name,
  • your rules ("pointers for nullable fields, int64 for IDs, omitempty only on optional fields"),
  • a request to list every place it guessed.

Check the generated types

Whatever produced the code, decode real payloads strictly:

go
dec := json.NewDecoder(f) // f is an opened file containing real JSON
dec.DisallowUnknownFields()
var p Product
if err := dec.Decode(&p); err != nil {
	log.Fatal(err)
}

DisallowUnknownFields makes any field your struct misses fail loudly. Try it on several payloads, including ones with null and missing fields.

Common problems and fixes

SymptomCauseFix
Fields typed interface{} or anySample had null, an empty array or mixed typesAdd samples or set the type by hand
Numbers decode as float64You decoded into anyUse typed fields, or Decoder.UseNumber() with json.Number
A field is always emptyTag does not match the keyGo matches keys case-insensitively, but underscores and hyphens must match
oneOf collapses into one loose typeNo union type in GoOne struct per variant, or json.RawMessage decoded once you know the variant
Odd or duplicate type namesGenerator naming from $ref pathsRename by hand
Nonsense output on a schemaSchema too convolutedCut it to the part you need, generate that, hand-write the rest

Checklist before you commit generated code

  • You reviewed every any or interface{} field.
  • Nullable fields are pointers or have a clear zero-value meaning.
  • IDs use int64 or string.
  • Strict decoding passes on real payloads, including ones with null and missing fields.
  • Type names read well.

If nothing works

If a generator fails or produces nonsense, report it to that project's issue tracker. Include the tool version, the exact command, and a minimal schema or sample that reproduces it.

text
Tool and version: quicktype (output of `quicktype --version`)
Command: quicktype --src-lang schema --lang go -o types.go schema.json
Expected: Go structs for the Item and Order types
Actual: <paste the error or the wrong output>
Minimal schema attached (reduced to the smallest case that fails).
Node.js version: <output of `node --version`>

Common questions

Does json-to-go work offline?

We have not tested it for this page. Check the project's own page for how it runs; writing the struct by hand or using the quicktype CLI is offline by design.

Can quicktype generate Dart?

Check quicktype --help for your installed version rather than relying on a list from the web, then try it on a real payload.

Why does my generated Go struct use float64 for IDs?

A single sample number gives the tool no way to know the range. Set the field to int64 or string yourself.

Clean up the sample first

Bytepliers, our Mac app of offline developer tools, cannot generate Go, Dart or C++ (its JSON → Types tool writes Swift and TypeScript only). Its JSON Formatter has a Lenient mode that repairs comments, trailing commas and single quotes and lists each fix, so the sample you feed a generator is valid JSON.

Every app.
One purchase.