Type generation

JSON to modelfrom one sample to five source files

Try the two-record example, then choose a target language and a root type name.

JSON to model

JSON input

The JSON is parsed and generated in this browser; no sample is uploaded or stored.

Generated model · Rust

Model options

All array records are scanned. Missing and null fields become nullable; review unknown types before use.

2 declarations · 2 nullable types

JSON to model turns a representative API response into a starting type. One array can show both records with different keys, so a field found only in the second record is not lost.

Use the generated declaration as a draft. A single response cannot establish business rules, future fields, exact decimal behavior or your project's serializer configuration.

Why use JSON to model?

Inspect every array record

JSON to model reads all objects in the top-level array. Fields missing from some records remain in the generated type as nullable rather than disappearing because the first record lacked them.

Two object cards with different keys combine into one model card, with a hollow marker on the optional field.

Switch the destination, keep the sample

The same local JSON becomes Rust structs, C# classes, Dart classes, PHP classes or Scala case classes. Each download carries the selected language's file extension.

One source card branches into several model cards and a structured output panel.

Make the sample prove the shape

01

Include different records

Place several objects of the same response shape in a top-level array. A key appearing only later becomes nullable, while nested arrays are inspected across their elements.

02

Choose the output contract

Rust emits Serde fields; C# uses System.Text.Json attributes; Dart includes fromJson and toJson; PHP and Scala emit model declarations that still need project-side hydration or codecs.

03

Export only the current result

Auto-generation waits 350 ms after edits. Turn it off to reveal Generate model or press Ctrl/Cmd+Enter. Any input or option change disables copy and download until the new run succeeds.

Five concrete model outputs

Rust and C# mappings

A JSON to Rust struct uses Serde rename attributes, Option and Vec. C# retains original keys with JsonPropertyName and uses nullable properties where the sample shows gaps.

Dart model constructors

The Dart model generator emits typed fields plus fromJson and toJson methods for nested objects and lists. Test generated code with your actual Flutter or Dart runtime.

PHP and Scala declarations

PHP 8 receives typed properties and array item docblocks. A Scala case class receives Option and List where evidence supports them; a codec is still a separate project choice.

Lossless inference step

This JSON to class generator reads number tokens before JavaScript can round them. Out-of-range or decimal values fall back to broad target-language types instead of a falsely precise integer.

What sample inference cannot know

Only five targets are offered
The selector contains Rust, C#, Dart, PHP and Scala. TypeScript, Go, Java, Python and Swift have their own tools; unavailable languages do not appear as working choices here.
A sample is not a schema
JSON Schema, OpenAPI and URL fetching are outside this JSON to model workflow. Required flags, ranges, enum members, dates and currency semantics cannot be proved from one sample.
Unknown numbers need review
Integer tokens inside signed 64-bit range get a narrow integer type. Larger integers and decimals get broad types; the generated application may still need a serializer setting for exact numeric round trips.
A declaration is not a complete application
PHP properties do not hydrate themselves from json_decode, and Scala case classes need a codec. Rust requires Serde dependencies. Generated code is not executed or compiled on this page.
Strict JSON and bounded output
Comments, duplicate keys, trailing commas and mixed top-level array values are rejected. The parser limits input to 500,000 characters, depth 100 and 50,000 nodes; output is capped at 1,000,000 characters.

JSON to model questions

Which target languages can the generator produce?

JSON to model supports Rust, C#, Dart, PHP and Scala on this page. The selector lists only these implemented outputs; each has a matching source-file extension.

How are null and missing fields represented?

All objects in the top-level array are examined. If a key is missing in some records or its value is null, the field becomes nullable where the target language supports that. A null-only field remains an unknown type.

Are nested objects and arrays supported?

Yes. Nested objects become named models, and arrays infer an item type from all visible elements. Mixed item kinds fall back to broad types that you should refine against more examples.

Can I rename the root model?

Yes. Root is the default. Enter an ASCII name starting with a capital letter; changing it regenerates the declarations and the downloaded filename.

Does generated code include JSON parsing methods?

Dart includes fromJson and toJson. Rust has Serde derives and C# has System.Text.Json key attributes. PHP and Scala outputs are declarations only, so your application supplies hydration or a codec.

Found a shape we should handle?

Generate a JSON to model draft

Run JSON to model with several realistic records, inspect the nullable fields and names, then download the current language's source file for project-side testing.