Come funziona
The first pass builds a type description from the sample. Each JSON value maps to a primitive — string, number, boolean, null, object or array — and objects and arrays recurse into nested definitions. Arrays are the interesting case: rather than assuming the first element is representative, every element is merged, so an array of objects where one element lacks a field produces an optional field rather than a missing one. A field that is null in any sample becomes nullable, and an array that is empty produces a placeholder type you must fill in yourself.
The output target determines naming. TypeScript interfaces are emitted with optional markers for fields absent from some elements and union types with null for nullable ones. Go structs use exported field names with JSON tags derived from the original keys, and pointer types for genuinely optional values so that the zero value stays distinguishable from absence. Python dataclasses use Optional with a default of None, and Rust structs use Option with serde attributes. In every case the goal is that the generated types describe the sample exactly, so a compile error later means the API changed rather than that the generator guessed.
Edge cases are handled explicitly rather than silently. A key that is not a valid identifier in the target language — containing a hyphen, a space or starting with a digit — is quoted or mapped to a valid name while preserving the wire name in the serialisation metadata, since breaking the mapping would make the code compile and then fail at runtime. Reserved words in the target language get the same treatment. Keys that differ only in case are flagged, because they collide in some languages and not others.
JSON Schema is the one target that describes rather than implements. It produces a draft-07 schema with types, required lists and nested definitions under $defs, which is useful for validating future payloads against the contract you inferred from today's sample. Remember that a single sample only proves what exists, never what is required: a field present in your sample may be optional in the API, and only documentation or a second sample can tell you which.
Casi d'uso comuni
- Generate TypeScript interfaces for an API response before writing the client that consumes it.
- Create Go structs with correct JSON tags from a webhook payload sample.
- Produce Python dataclasses for a config file so your editor can autocomplete it.
- Build a JSON Schema from a sample payload to validate future messages in a test suite.
- Create SQL DDL for a staging table that matches the shape of an incoming JSON feed.
- Compare the optionality of fields between two samples to see which are genuinely always present.
Ultimo aggiornamento: 2026-10-14 — il corpo dell'articolo è mostrato in inglese; l'interfaccia è tradotta.