Instantly generate Kotlin types and serializers from JSON

quicktype can now generate Kotlin types and serializers from JSON sample data. Here's the Pokémon sample running in a quicktype playground, demonstrating Kotlin, Java, and Swift code generated from the same sample JSON data:

{ "pokemon": [ { "id": 1, "num": "001", "name": "Bulbasaur", "img": "http://www.serebii.net/pokemongo/pokemon/001.png", "type": [ "Grass", "Poison" ], "weaknesses": [ "Fire", "Ice", "Flying", "Psychic" ], "next_evolution": [ { "num": "002", "name": "Ivysaur" }, { "num": "003", "name": "Venusaur" } ] }, { "id": 2, "num": "002", "name": "Ivysaur", "img": "http://www.serebii.net/pokemongo/pokemon/002.png", "type": [ "Grass", "Poison" ], "weaknesses": [ "Fire", "Ice", "Flying", "Psychic" ], "prev_evolution": [ { "num": "001", "name": "Bulbasaur" } ], "next_evolution": [ { "num": "003", "name": "Venusaur" } ] } ] }

As usual, quicktype will:

  • Infer nice class and property names
  • Generate convenient fromJson and toJson methods for top-level types, including top-level arrays and maps
  • Deduplicate types inferred to be the same
  • Detect enums and emit custom marshaling code for them
  • Detect heterogeneous JSON data and emit sealed classes with custom marshaling code to keep your Kotlin typesafe
  • Distinguish Map<String, *> from custom object types automatically using Markov chains

We've initially targeted the Klaxon JSON library and we invite the community to contribute support for other libraries. This is quicktype's second JVM language and we expect Scala support to land soon!

Open this sample in quicktype.

David

David