A service returns JSON and your application needs a model for it. You could write out each property by hand, but that becomes tedious when the response contains nested records and lists. Generating a model can give you a starting point. The quality of that starting point depends on whether the sample shows the types and variations the application will actually receive.
TinyToolbox JSON Type Generator reads sample JSON and produces TypeScript, Python with Pydantic, C#, Go, Rust with Serde, Kotlin with kotlinx.serialization, or JSON Schema. It infers shapes from the values you provide. Use the resulting code or schema as a draft and check it against the documented contract and representative fixtures.
Choose samples that show real variation
Begin with a payload whose root matches the data the model will describe. If consumers receive an object with sessions and nextPage, include that whole object when you want a response model. If you only need a model for an individual session, paste one session object or an array of sessions to show the range of fields an item can have. The array produces a root type for the list, with the item shape inferred from its contents.
Avoid selecting just the tidiest response. Include several records when a field can be absent or null. A sample where each row has a room will suggest that room is always provided. A sample where every room value is null cannot show that it might also be a string. If the service documentation calls a field optional, check that your example demonstrates the omission or adjust the generated model yourself.
Use synthetic values for examples that might be committed or shared. You can replace names, addresses, and identifiers with fictional values while keeping their shapes. Preserve the distinctions relevant to inference. A string ID beginning with zeros should still be a string in the sample. If one record omits a key, the fictional copy should omit it too.
Generate a model in TinyToolbox
- Open JSON Type Generator.
- Paste the example into JSON input, or select Load example to see the built-in sample.
- Choose an Output language.
- Enter a descriptive Root type name, such as WorkshopResponse.
- Select Generate code and inspect Generated code.
- Choose Copy or Download once the output is ready for review in your project.
The input is processed in your browser. The generator accepts up to 500,000 characters and supports up to 64 levels of nesting. The root name starts with an ASCII letter and can contain up to 64 letters, digits, or underscores in total. The model name can be normalized to suit the generated code. Check the name and file extension before adding the result to your project.
If the tool reports malformed JSON, use JSON Formatter & Viewer to check the sample separately. Paste the value itself and omit any prose, headers, or code fences from its source. A valid sample can still lead to an unsuitable model if its shape is different from the actual response, so verify the root after the parser accepts it.
Use an example with optional and nullable fields
Consider this synthetic response for a workshop listing:
{
"sessions": [
{"id":"0017","title":"Welcome","room":"North hall"},
{"id":"0042","title":"Seed starting","room":null,"seats":12},
{"id":"0050","title":"Questions","seats":8}
]
}
The generator looks across the objects in the sessions array. Each record has an id and a title, so those fields are present in every observed item. Some rows omit seats, which makes it optional. The observations for room include a string, a null, and an omission. Check the generated model for all of those cases.
Optionality describes whether a key can be absent. Nullability describes whether a present key can have null as its value. Some model targets distinguish those cases directly, while in others the generated representation can use the same nullable construct for absence and null. When your application needs to tell those states apart, inspect what the target serializer does on real input. Use fixtures with missing, null, and populated values instead of relying on one happy-path example.
The id is a string even though it consists of digits. In a model it can carry 0017 without losing the leading zeros. The seats values are numeric. The generator looks at the sample’s numeric tokens when inferring integers and numbers, but some language targets use the same type for both. If the contract permits a decimal, include one in the sample or adjust the model accordingly.
Check nested objects and mixed arrays
The generator creates nested models for object shapes. If each session has a venue object with a name and room code, check the generated venue type as well as the session type. A venue example from only one record can miss fields that appear in other records. Include those examples in the same array when they describe legitimate variations of the item shape.
A list of mixed values may need a union or a general JSON value type. For example, if value is a number in one record and a string in another, TypeScript and Python can express the mixed observations as a union. Other model targets can use a generic JSON type for mixed fields. Check whether the mixed input is truly part of the service contract. An unexpected string in a numeric field could be a defect you want to catch, rather than a type you want to accept everywhere.
An empty array shows that a field can be an array, but it provides no evidence about the element type. Include a populated case if you have one. Likewise, a null-only field does not show what type is used when a value eventually arrives. When the sample cannot demonstrate a case, consult the contract rather than assuming the absence of evidence is a permanent restriction.
Review names and serializers in the target language
A JSON key such as display_name or room-number can be a valid string key even when it is awkward or invalid as a source-language property name. Generated models may use a different identifier and supply a mapping to the original JSON name. Check that mapping in the target language. Read a fixture containing the original key and serialize the model back if the application sends it.
Check the target’s imports and project conventions before copying code into an existing application. A Pydantic model belongs in an environment that uses Pydantic. A Rust model intended for Serde needs the serialization setup used by that project. A generated model file can show the intended declarations and still need namespace, package, module, or import adjustments to fit your codebase.
For TypeScript, remember that a static declaration helps the compiler but does not establish that a runtime value meets the type. Parse and validate responses at the appropriate boundary when your application relies on that guarantee. In other targets, test that the serializer handles missing and unknown fields the way you expect rather than inferring behavior from the model’s appearance.
Use JSON Schema when the next step is validation
Select JSON Schema if you need a schema document to pass to a compatible validator. Review the generated properties, required lists, item schemas, and mixed-type variants. The tool generates its schema from observed shapes. It does not infer business limits such as a positive seat count, a date format, or a set of allowed status values merely from one or more examples.
Suppose all observed sessions have between 8 and 20 seats. A generated integer field does not encode that range. Add a range only if it is part of the contract. Similarly, a string that happens to contain a date can still be inferred as an ordinary string. Add the date rule through your validation workflow and test it against valid and invalid cases.
Test the schema on new examples rather than only the source that produced it. Include an intentionally invalid object and check that it fails for the intended reason. That catches a schema that accepts the sample but also accepts an incomplete payload your application cannot use.
Integrate the model with a few concrete tests
Copy or download the generated output, then run your project’s normal compiler or validator. Test a complete record, one that omits an optional key, and one containing an explicit null. Include an empty array and a populated array when both can occur. If the service can introduce new fields, check whether your application should accept or reject them.
For a changing API, compare a new synthetic response with the old fixture using JSON Difference Checker. Decide which changes belong in the contract, update the sample, and review any differences in the generated draft. Keep the sample with the model where that fits your repository, so a later reviewer can see the examples that informed the design. The model is ready when it handles the documented cases and passes the checks in the application that will use it.
Compare an empty response with a populated response
Imagine an inventory API returns an object with a results array. A search for an unavailable item returns {"results":[]}. Run that sample in JSON Type Generator and inspect the type for results. The shape gives evidence that results is an array, but the sample has no item from which to infer a model. Save the empty response as a test case and find a representative populated response for generation.
For example, a populated response could contain {"results":[{"code":"0123","quantity":4,"tags":[]},{"code":"0570","quantity":0,"tags":["clearance"]}]}. Check that the generated record represents code as a string and that both kinds of tag arrays are accepted. The second item provides evidence about the tag element type. Zero is a present numeric value, so distinguish it from an omitted quantity or a null if the API permits those states.
Test the generated model with both the empty and populated payloads. For the empty case, check that it accepts an empty list of results without trying to create a placeholder item. For the populated case, check that the code retains its leading zero and that the second item’s quantity stays zero. A comparison at this level can catch a serializer or default value that interprets valid zero counts as missing data.
Review an inferred type when the API contract is broader
Suppose the documented API also sends a boolean backordered field when an item is handled by a different fulfillment system. The samples above give no evidence of that property. Include a real representative example with it if you have one, or adjust your application’s model using the documented field definition. Verify both a present boolean and a record where the property is omitted. If the presence of the field changes behavior in your application, add a check for that behavior after parsing.
When keeping examples for another developer, label which items come from the public contract and which were observed in test responses. A generated type is an inference from the pasted data. A fixture with no tags and a fixture with tag strings give you two repeatable checks, while the service specification determines what other cases the integration must handle. Save the input and generated output with the target language or schema selection so you can reproduce the comparison after a model change.