🧩

JSON to Model Generator

Turn JSON into nine language models, a Zod validator and JSON Schema with nested, array and nullable fields.
Models 📂 Developer 👤 ToolCMS 🏷️ v1.1.5 ⚙️ clipboard

JSON 输入 对象或对象数组均可

生成选项 改选项后即时重算

数组会合并所有元素,嵌套数组里的对象也会补齐字段;字段缺失会标记为可空。

结构摘要 类型、字段与嵌套层级

模型与校验 按输出切换,可直接下载


        

How to Use

📖 What it does

After an API returns JSON, the slow part is often not the request. It is copying the fields into models for eleven output formats. Go structs need tags, Java needs Jackson annotations, Python needs Optional handling and defaults, C# needs properties, Rust needs serde derives, and PHP needs typed properties. Once fields grow and nesting deepens, manual copying misses keys, and arrays and nulls are easy to mistype.

This generator reads JSON and recursively infers objects, arrays, strings, integers, floats, booleans and nulls. Nested objects become separate types, array elements are merged, and fields missing from later records are marked nullable. The right panel switches among the eleven output formats, with controls for root type, package or namespace, field style and optional handling. The result is readable model code, not a runtime serializer.

No compiler is called and no JSON is uploaded. Use it to sketch a model before API integration, or to turn a pile of field notes into a structure. Whether the code compiles and matches team conventions still has to be checked in the real project.

✨ Features

  • Eleven outputs: Go, Java, Python, C#, Rust, PHP, TypeScript, Kotlin, Swift, Zod and JSON Schema.
  • Recursive inference: objects become named types, arrays become `[]T`, `List`, `Vec`, `Array` or `[T]`, and integers stay separate from floats.
  • Root-array merging: every object contributes fields, missing keys become nullable, and newly seen keys are added to the type.
  • Nullability and wire names: `null` maps to pointers, `Optional`, `Option` or nullable types, while Go tags, Jackson, C# attributes and serde keep original keys.
  • Naming controls: root type, package or namespace, camel/snake/Pascal styles, plus optional, wire-name and omitempty switches.
  • Structure summary and schema: type, field and depth counts, root shape, and a Draft 2020-12 JSON Schema export.

🚀 How to use it

  1. Paste an object or an array of objects and confirm the JSON is valid; root arrays merge fields from every object.
  2. Set the root type and package, then choose the field style and the optional, wire-name and omitempty switches.
  3. Switch across the eleven output tabs and inspect nested objects, arrays, null fields and reserved-word changes.
  4. Read the structure summary; when more than 24 types appear, consider splitting the input.
  5. Copy or download the code and run the language formatter or compiler; the schema output can drive contract validation.

⚠️ Before you rely on it

  • JSON must be valid: trailing commas, single quotes and comments fail parsing; the error points at the problem but does not repair the source.
  • Root arrays need object elements: empty or scalar arrays cannot infer fields; wrap the payload as `{ "items": [...] }` first.
  • Inference is not runtime validation: conflicting field types collapse to `any` or `Object`; the real API should use one type per field.
  • Nullable is not optional: `null` means the key exists with an empty value, while a missing key means an unstable shape; both become nullable here.
  • Reserved words are renamed: `class`, `type` and `default` gain a suffix, while serialization annotations keep the original JSON name.
  • Swift uses the generated `JSONValue` for arbitrary values, and Kotlin needs Jackson annotations; compile the result before shipping it.

Related

⏫︎