quicktype's big debut

quicktype is now open source, targets seven languages, offers a web app, a command line client, and even has its own Slack!

Let us explain why quicktype is useful, what makes it special, and how you can get involved.

quick… what?

quicktype infers types from sample JSON data, then outputs strongly typed models and serializers for working with that data in your desired programming language. In short, quicktype makes it a breeze to work with JSON type-safely. For more explanation, read A first look at quicktype.

Doesn't _______ already do that?

Some existing tools claim to translate JSON to Go, C#, Swift, Java, and other popular languages, but they often support only one target language and contain many obvious bugs (most of quicktype's samples cause these tools to fail). They usually work by traversing a parsed JSON value and emitting types naively, causing duplicate classes with identical properties, invalid names, and other blatant errors. They also do not output serializers and deserializers for converting between JSON and the model, so reading and writing the data is left as a puzzle for the programmer.

quicktype uses an intermediate representation to perform some sophisticated operations before rendering code: type unification, map detection, keyword substitution, name inference, name collision avoidance, and more. All of this work is language-agnostic, so the same engine outputs Swift, Go, Java, C#, Elm, TypeScript, and JSON Schema at the moment. We hope the community will contribute many more backends.

quicktype also outputs serializers and deserializers, so you can read and write JSON immediately. For example, in Swift, quicktype generates convenience constructors via extensions on your model types, so working with JSON is as easy as:

let person = Person(fromString: "{ \"name\": \"David\" }")!
let json = person.jsonString!

In C#, quicktype provides serializers via extension methods, and deserializers via static methods on partial classes, so you get ideal ergonomics while keeping your POCOs tidy:

var person = Person.FromJson("{ \"name\": \"Mark\" });
var json = person.ToJson();

In TypeScript, quicktype generates interfaces for your data, but also outputs a type representation to dynamically check the result of JSON.parse at runtime, providing more safety than merely casting the result and hoping for the best. We're eager to apply this technique to other dynamic languages including JavaScript, Ruby, and Python.

Wait, there's more!

One of quicktype's more interesting features is its support for heterogenous data (extremely common in JSON) via union types. For example, given the JSON string [1, “1”], quicktype infers Array<Int | String> rather than Array<object>. Other JSON-to-types tools get this wrong, losing important information.

quicktype also provides a CLI with even more power; the CLI can, for example, crawl multiple API endpoints and unify all of their responses into coherent types. More on this later.

Want to get involved?

We'd love for you to try quicktype and give us feedback. Does it work for you? Does anything seem unnatural? What could we improve? File an issue or chat with us on quicktype.io (click the chat widget in the lower-right).

We're also looking for collaborators. If quicktype seems interesting to work on, you can begin contributing by watching quicktype Inside Out: Episode 1:

You can read more about quicktype internals in quicktype under the hood.

What's next?

Some features we'd like to explore next include:

  • tuple support
  • special handling of Dates, GUIDs, URLs, and Base64 blobs
  • backends for dynamic languages, including JavaScript Flow annotations
  • IDE/editor integration

If you'd like to work on any of these, please check out quicktype on GitHub or say "👋" on Slack. Thanks!