Generator

JSON to code

Paste a payload and get typed classes for your language. Array elements are merged before generating, so a key missing from some elements becomes an optional field instead of being lost.

Sample JSON
Waiting for input.
Generated code

Generated from one sample, so treat optionality and numeric widths as a first draft. ⌘/Ctrl + Enter runs it again. Everything happens in this browser — nothing is uploaded.

About the JSON to code generator

Turning an API response into model classes by hand is busywork. Paste the payload and get types for your language, with the serialisation attributes that language expects. Array elements are merged before generating, so a key that appears in only some elements becomes an optional field rather than being lost — the mistake most generators make when they read only the first element.

How to use it

  1. Paste a representative payload — include elements with optional fields present and absent.
  2. Pick the language, name the root type, and choose whether to emit serialisation annotations and nullable optionals.
  3. Copy the code, or download it as a file named after the root type.

Questions

Which languages are supported?

C#, TypeScript, Dart, Kotlin, Java, Python and Go. C# emits [JsonPropertyName], Kotlin @SerialName, Java @JsonProperty, Go json tags with omitempty, and Dart gets fromJson/toJson methods.

How are optional fields handled?

A key missing from any element of an array is treated as optional: nullable in C# and Kotlin, `?` in TypeScript, Optional[...] with a default in Python, a pointer in Go.

What happens with mixed types?

integer and floating-point values in the same position widen to the language's floating type. Genuinely mixed types (a string and an object, say) fall back to the language's open type — object, unknown, dynamic or interface{}.