How to Generate Typed Models from JSON Without Sending API Data Online
Review a saved JSON response, choose a root model and generate C#, TypeScript, Kotlin, Python or Go types locally while checking inference limits.
Turning a JSON response into typed models can save time, but generated code is only a starting point. A tool can infer shape and nullability from the sample in front of it; it cannot know every value an API may return tomorrow.
API Model Forge generates C#, TypeScript, Kotlin, Python and Go models from JSON locally on Windows. The useful workflow is to generate quickly, then review the result against the real API contract.
Use representative JSON, not the smallest sample
If your sample contains only one successful response, the generated model may miss optional fields, error shapes or values that appear only in other cases.
Prefer a sample that represents the data you actually expect. If the API publishes an OpenAPI or JSON Schema contract, treat that contract as more authoritative than one captured response.
A generator sees what you give it. If a property never appears in the sample, it cannot infer that property.
Remove secrets before sharing samples
API responses can contain tokens, email addresses, customer records, internal IDs or other sensitive information.
API Model Forge processes JSON locally and does not fetch responses or upload content. That helps when you do not want to paste data into an online generator.
Even so, keep good hygiene:
- use test or synthetic data where possible;
- remove credentials from saved samples;
- do not commit production responses into public repositories;
- review generated comments or examples before sharing code.
Local processing reduces exposure; it does not make sensitive source data safe to publish.
Validate the JSON first
Malformed JSON should not produce confident models.
Typical problems include:
- trailing content after a valid JSON value;
- duplicate object keys;
- missing commas;
- unclosed strings or objects;
- invalid escape sequences.
API Model Forge rejects malformed trailing JSON and duplicate keys before generation. That matters because duplicate keys can be interpreted differently by different parsers, making the source ambiguous.
Fix the source or obtain a clean response rather than generating from ambiguous data.
Choose a meaningful root type name
The root name becomes part of the generated code. Use a name that represents the domain object rather than a temporary filename.
For example:
CustomerResponseInvoiceListWeatherResultUserProfile
Avoid vague names such as Data when the model will live in a larger codebase.
API Model Forge lets you choose the root name before copying or saving the output.
Review nullability carefully
One of the hardest things to infer from a sample is whether a field is optional, nullable or always present.
Consider these cases:
- property missing entirely;
- property present with
null; - property present with an empty string;
- property present in some array elements but not others.
These states can have different meanings in an API.
A generator can make a reasonable inference from observed examples, but your application should follow the actual contract. Review nullable types and optional members before treating the generated model as production-ready.
Arrays need more than one representative element
If an array contains only one object, the generator sees only that shape. Real APIs may return elements with additional optional fields or different values.
Mixed object shapes can be merged conservatively, but you should still verify the result. If the API intentionally returns different object types in the same array, a simple generated class may not express the domain correctly.
Use schema documentation or several representative responses when available.
Property names can collide after normalization
JSON keys can contain spaces, hyphens, punctuation or names that are reserved words in a programming language.
Different wire names can also normalize to the same code identifier. For example, hypothetical keys such as user-id and user_id may collide under a naming convention.
API Model Forge resolves normalized-name collisions deterministically and handles reserved or unusual identifiers. But when a generated field name differs from the JSON wire name, your serializer still needs the appropriate mapping behavior.
The generated output should therefore be reviewed in the context of the JSON library your project uses.
Language-specific review matters
C#
Check nullable reference types, numeric choices and serializer naming behavior. Decide whether your project prefers classes, records or other conventions beyond the generated baseline.
TypeScript
Interfaces describe compile-time shape; they do not validate runtime JSON. If data crosses a trust boundary, consider runtime validation separately.
Kotlin
Review nullable properties and serializer annotations. JVM property naming can create getter conflicts, so unusual wire names may require explicit mapping.
Python
Dataclasses are useful structure, but they do not automatically validate external JSON. Renamed fields may need mapping in whichever serializer/deserializer you use.
Go
Review pointer vs value choices, numeric types and JSON tags. Unusual wire names should be preserved through explicit tags or methods.
Numeric inference has limits
A JSON number does not tell you its complete business meaning.
A value that looks like an integer in one sample may later exceed a smaller integer range. A decimal-looking value may represent money and require decimal semantics rather than binary floating point. A numeric-looking identifier may actually need to be a string.
Do not let a one-value sample decide critical domain types without review.
A practical generation workflow
- Save or copy a representative JSON object.
- Remove credentials and unnecessary personal data.
- Validate that the JSON is complete and unambiguous.
- Open it in API Model Forge.
- Choose a meaningful root type name.
- Generate the language you need.
- Review nested types, arrays, optional fields and nullability.
- Review renamed or unusual property names.
- Compare the result with the API documentation or schema.
- Add project-specific serializer annotations, validation and tests.
Then test deserialization against more than one real or synthetic response.
Do not confuse model generation with API integration
API Model Forge does not call APIs, manage authentication or keep generated code synchronized with a remote schema. It converts the JSON you provide into a typed starting point.
That separation is useful for privacy and predictability, but it means updates are your responsibility. If the API changes, regenerate or update the model and review the diff.
Keep generated code maintainable
Generated code should fit the project around it. Before committing:
- apply your formatter;
- run the project’s compiler or type checker;
- add serializer settings used by the codebase;
- add tests for representative payloads;
- remove unused models created from irrelevant sample branches;
- document any manual changes you expect to preserve.
If you regenerate later, compare the output rather than replacing customized code blindly.
The best use of a JSON model generator is not “one click and done.” It is fast structural scaffolding followed by contract-aware review.