Show HN: quicktype converts JSON, TypeScript, GraphQL to types in 18 languages
app.quicktype.ioHello, HN!
quicktype generates types and serializers from JSON, JSON Schema, TypeScript, and GraphQL queries, to help you use JSON type-safely in many languages: C#, Go, Rust, Crystal, C++, Objective-C, Java, TypeScript, JavaScript, JavaScript PropTypes, Flow, Swift, Kotlin, Elm, JSON Schema, Ruby, Dart, Python, Pike, and our latest language, Haskell.
quicktype has some remarkable features that differentiate it from other JSON converters:
Type inference: quicktype infers optionals, dates, UUIDs, enums, integers, and unions. It also infers maps (versus objects) using a Markov chain.
Careful naming: quicktype’s naming system creates nice, legal, unique names for types and properties, handling reserved words and tricky corner cases (e.g. `{ “”: “this is legal”, “null”: “so is this”, "1;DROP TABLE users”: “and this" }`).
Unions for heterogeneous data: JSON data is often heterogenous. quicktype infers this, and creates union types in languages that support them, or synthetic union types in languages that don’t (e.g. try quicktyping `[0, “zero”]` as Swift and Go).
Type unification. This works across multiple samples, so you can quicktype a directory of API data, for example, and unify types across all responses (e.g. you’ll get just one `Customer` type, even if customer data occurs in many samples). You can also provide multiple samples for the same type for better coverage.
Marshalling code: In addition to types, quicktype generates functions for marshalling your types to and from JSON.
Supports dynamic languages: quicktype can add dynamic typechecks for JavaScript, TypeScript, Flow, Python, and Ruby.
Convenient CLI: Run `quicktype https://blockchain.info/latestblock -o LatestBlock.ts` to quicktype a Bitcoin API in TypeScript.
Private hosted app: https://app.quicktype.io/ runs quicktype on the client, so servers never see your data (most JSON converters send your JSON to their server)
Typed input: Feed quicktype TypeScript or JSON Schema instead of JSON for better control over generated types.
Code quality: quicktype emits clean code
Hey, huge fan here!
It's really incredible to take a master type-definition in TS/JSON Schema and generate language bindings in every language. Especially from a JS/TS Node script as part of a build pipeline.
Or to start new type definitions by using API output/JSON files.
Thanks a lot! Glad you like it.
I do the same workflow, where I generate types during build. I often generate them directly from the datasource (e.g. directly from the API). Then I get compile-time errors if the API changes.