Salesforce Dictionary - Free Salesforce GlossarySalesforce Dictionary
Data & queries

JSON → Apex DTO Generator

Generate Apex inner classes from a JSON sample. Each nested object becomes its own class; array element types are inferred.

JSON

Apex

Output appears here.

Related dictionary terms

§

About this tool

When you call an external REST API from Apex, you typically deserialize the response into a typed inner class with `JSON.deserialize`. Writing those classes by hand from a sample response is mechanical and error-prone. This generator takes a JSON sample, walks the structure, and emits an Apex outer class with one inner class per nested object - types inferred from the values you provide.

How it works

The generator parses your JSON sample, recurses into each object, and produces a strongly-typed Apex class. Numbers become `Decimal` (or `Integer` if no fractional part is present anywhere in the sample), booleans become `Boolean`, strings become `String`, arrays infer their element type from the first element, and nested objects each become their own inner class with PascalCase names derived from the JSON key. The output is paste-ready into an Apex class file.

When to use it
  • Bootstrapping a typed Apex DTO for a third-party REST response (Stripe, HubSpot, Twilio, etc.).
  • Generating fixtures for an Apex test class that calls a mocked HTTP endpoint.
  • Documenting the shape of a webhook payload as part of an integration spec.
§

Frequently asked questions

What if my array is empty in the sample?
The generator falls back to `List<Object>` and adds a comment so you can replace it with the right element type once you have a non-empty sample.
How does it handle reserved Apex keywords as JSON keys?
It appends `_x` to any field name that collides with an Apex reserved word and adds a JSON.deserialize hint comment so the field still maps correctly.
Does it support deeply nested or recursive structures?
Yes for nested. Recursive (self-referencing) JSON is rare and not specifically handled - the generator will emit two separate classes with the same shape if you have one.