Every time I added a field to my JSON, I had to update two files. Every time I renamed a property, two files. That kind of tedium is what computers were invented for.

The idea came from F# type providers, which generate static types at build time from sample data. Point one at a JSON file, and you get a type with autocomplete in your environment. I was learning Swift at the time, building model objects by hand, and talked to Mark about it. We agreed: let's solve this for every language.

quicktype is an open-source tool—CLI and interactive website—that infers types from JSON and generates code in TypeScript, Swift, Go, Java, Python, C#, and more. Not just type definitions: it creates all the marshalling functions too, so you can parse JSON into structs and serialize back.

The interesting challenges are in the edge cases. JSON is heterogeneous—an array might contain both numbers and strings. Most tools would give up and type it as object. quicktype creates a union type instead, preserving the type information. In Swift, that's a native enum with associated values. In Go, it's a synthetic struct with pointers. We try to represent the data faithfully in every language.

Map detection was one of our cleverest features. If your JSON has keys like "1895", "1896", "1897", quicktype recognizes those aren't fixed property names—they're dynamic keys. It generates a map type instead of a class with properties named after years.

quicktype also handles optional properties (inferring when a field is sometimes missing) and transformers (converting stringified numbers to actual numbers in the internal representation).

quicktype was the precursor to Glide. If we can infer types from data, why can't we infer entire applications?