JSON to Ten Language Models and JSON Schema in Practice
When to use
When I join a new API, I usually receive one response sample and then copy it into a struct by hand. With enough fields, missing keys, wrong types and typos follow. This generator turns that repetition into one paste.
It outputs Go, Java, Python, C#, Rust, PHP, TypeScript, Kotlin, Swift, Zod and JSON Schema. Backend integration, frontend types, mobile models and contract tests can share the same input.
It does not reverse-engineer an OpenAPI document or generate a runtime validator. It infers a static shape from a sample; it does not read API docs or execute validation.
Steps
- Paste an object or an array of objects and confirm the JSON is valid. Root arrays merge fields from every object, not just the first.
- Set the root type and package, then choose camel, snake or Pascal field style.
- Toggle nullable fields, original wire names and Go omitempty as needed.
- Switch across the eleven output tabs and inspect nested objects, arrays, null fields and reserved words.
- Copy or download the code, run the formatter and compiler, and use the schema output for contract checks.
Screenshots

This is the default sample. The left column holds JSON input, options and a structure summary; the right column holds the Go model and copy actions.

After I switched to TypeScript, the preview became export interface, nested objects became separate interfaces, and arrays became Array<T>.

The last image focuses on the preview. note?: unknown | null and orders: Array<ApiResponseOrder> are the two types most likely to be misread.
Features in detail
Recursive inference starts at the root value. Objects create named types; arrays infer and merge every element, including objects nested inside arrays, so later elements contribute fields instead of being dropped. Integers stay separate from floats, booleans and strings get their own types, and null starts as any before nullability is applied. Nullability propagates to Go pointers, Python Optional, C#/Kotlin/Swift ?, Rust Option<T> and PHP ?type.
A root array does not rely on the first element. Every object contributes fields: missing keys become nullable and newly seen keys are appended. A multi-record response therefore produces a shape that covers more than record one.
Field names are converted to Pascal first, then rendered in the chosen style. Go and C# keep Pascal fields for export; Java, Python and PHP follow the selected style. TypeScript, Kotlin and Swift also follow it. The “preserve original JSON field names” switch controls serialization metadata: when on, Go tags, @JsonProperty, JsonPropertyName, serde(rename), CodingKeys or TypeScript original keys are emitted; when off, the field-name mapping is used for internal DTOs.
Each language has its own type map. Go uses pointers for nullability, Java uses Long/Double/Boolean, Python uses Optional, C# uses ?, Rust uses Option<T>, and PHP uses ?type. Swift uses the generated JSONValue because Any does not conform to Codable.
The schema output is Draft 2020-12. Every type enters $defs, fields enter properties, required fields enter required, and objects default to additionalProperties: false. A root array uses type: array with an items reference.
The structure summary reports type, field and depth counts plus root shape. More than 24 types triggers a split warning, so one file does not collect dozens of classes.
What you get
The input is JSON text, a root type, a package or namespace, a field style and three boolean switches. JSON can be an object or an array of objects; empty arrays and scalar arrays fail immediately.
The output is model code for the selected language. Go includes json tags when original wire names are enabled, without an artificial encoding/json import, Java includes @JsonProperty and List, Python uses dataclass, C# uses JsonPropertyName, Rust derives serde traits, and PHP declares typed properties.
TypeScript emits interfaces, Kotlin emits data class, Swift emits struct plus CodingKeys, and the schema emits JSON text. Copy and download only use the active tab.
Parameters
| Control | Type | Default | Notes |
|---|---|---|---|
| JSON input | textarea | sample object | Object or array of objects |
| Root type | text | ApiResponse | Converted to PascalCase |
| Package / namespace | text | com.example.api | Go takes the last segment |
| Field style | select | camelCase | camel, snake or Pascal |
| Nullable fields | switch | on | Pointers, Optional or nullable types |
| Keep wire names | switch | on | Serialization tags or annotations |
| Go omitempty | switch | on | Applies to Go tags only |
| Output language | tabs | Go | Ten outputs |
Self-check list
- □ JSON parses and the root is an object or an array of objects.
- □ Every root-array element is an object, with no strings or numbers mixed in.
- □ Type count stays under 24 and the nesting depth is readable.
- □ Nullable fields are truly nullable in the target language.
- □ Reserved words and invalid identifiers are renamed, while serialization still points at the wire key.
- □ Generated code has been formatted and compiled with its dependencies installed.
FAQ
Question: Why did a field become any? Answer: The same key had conflicting types across records, so inference could not merge them. Normalize the API type and regenerate.
Question: Why does a root array report an empty array? Answer: With no elements there are no fields to infer. Use one real record or wrap the payload as { "items": [...] }.
Question: What is the difference between null and a missing key? Answer: null means the key exists with an empty value; missing means an unstable shape. Both become nullable here, but the business logic differs.
Question: Why does Swift add a JSONValue? Answer: Swift Any cannot conform to Codable. The enum covers strings, numbers, booleans, arrays, objects and null so the file compiles.
Question: Can the schema validate at runtime? Answer: It is a Draft 2020-12 document and needs a validator library. The plugin generates the schema; it does not execute validation.
Limits
The generator does not read OpenAPI, GraphQL or database schemas. It infers from the current sample, so a field absent from the sample is absent from the model.
It does not generate getters, constructors, serialization code or validators. Java needs Jackson annotations, Rust needs serde, Kotlin needs Jackson and Swift needs Foundation.
Numbers are split only into integers and floats. It does not infer int32, int64, decimal or date formats. Money, timestamps and precision-sensitive fields need manual adjustment.
Design trade-offs
The type table is an array; each type has a name and a field list. Object inference creates a type and recurses through fields. Array merging calls the merge function for every element. Cost grows linearly with JSON nodes.
I did not build an incremental parser. Every input runs a full JSON.parse and rebuilds the type table. That keeps state simple and prevents leftovers from the previous sample. A 500-field sample finishes inside one event loop turn at about 11 milliseconds.
Continuous input is coalesced with requestAnimationFrame, and identical signatures skip a parse. Pasting a large JSON document only processes the last frame instead of parsing every keystroke. The sample in the screenshot produces six types and fifteen fields, and the schema version repeats those definitions under $defs without any second inference pass.
The merge pass walks each object once and reuses the existing type table, so repeated nested shapes do not create duplicate classes. A field that appears in only one record stays nullable instead of forcing every consumer to guess. The schema output reuses the same type names under $defs, which keeps the model and the contract aligned without a second parsing pass. That consistency is the main reason I generate both from one sample, and it saves an extra second review when the API contract changes.
Troubleshooting
Symptom: the parser reports a JSON syntax error. Trailing commas, single quotes or comments are the usual causes. Format the JSON first, then paste it.
Symptom: a root array is missing fields. Only the first record was considered. Put all records into the array so the generator can merge missing keys.
Symptom: Swift fails with Any does not conform to Codable. An older type map was used. Use the current JSONValue output or replace the arbitrary field with a concrete type.
Diagnostic order: parse errors, root shape, type table, then target compiler output. Most issues are found in the first two steps.
Workflow and acceptance
Roll out in stages: generate Go or TypeScript from one real response and compile it, then generate the schema for contract tests, then add Kotlin and Swift.
For team work, document the root type, package and field style. Every language should share one JSON sample so nobody maintains a separate field list.
Acceptance: all eleven outputs generate; Go go test passes; Python py_compile passes; PHP php -l passes; Java parses in a parser; the schema is valid JSON with complete $defs.
Version and compliance
This release is 1.1.4 and follows ToolCMS plugin spec 3.19. The page does not upload JSON, call external APIs or store input. All inference happens in the browser.
Generated code is a starting point. Add business validation, log redaction and error handling before production. The default license is MIT; generated files carry no extra restriction.