Yesterday we launched a preview of quicktype. Here's a brief explanation of what it is.
For programmers
quicktype infers types from sample data (e.g. JSON), then outputs typed code in your desired programming language (C# and Go are available to start but more are planned).
There are a few simple tools that do this already, but quicktype is already a bit cleverer:
- meaningful type names are guessed from names in data
- equivalent types with different names are unified
- quicktype optionally outputs de/serialization helpers
- quicktype is smarter about maps/dictionaries
- quicktype synthesizes union types for heterogeneous data
- quicktype works locally and doesn't transfer, retain, or share your sample data
For everyone else
Apps and web services communicate with each other over the Internet by sending and receiving 'documents' of data. Here's an example of the kind of data Pokémon Go might download about nearby pokémon from a server:
{
"pokemon": [
{ "name": "Pikachu", "cp": 582, "hp": 44 },
{ "name": "Bulbasaur", "cp": 123, "hp": 32 }
]
}
Before you can toss a pokéball, the app needs to translate the downloaded data into a structured representation so it can be filtered, transformed, or displayed graphically.
The structured representation, also known as the type of the data, is what allows the app to 'ignore', 'show pictures', 'prioritize', or do anything else meaningful with the downloaded data. The programmer writes code to define the type of the data.
This is not difficult code for a programmer to write—in fact, it's trivial and boring! That's where quicktype comes in.
Given sample data, quicktype automatically derives its type and writes the code needed to work with that data. It writes the boring code for the programmer, so she can save time and focus on the interesting stuff.