Skip to content

JSON to Apex Class Generator

Paste a JSON payload and get typed Apex wrapper classes with a parse() method.

Runs in your browser. Nothing is uploaded.

JSON input

Try an example

Apex output

3 classes, 14 properties
/**
 * Apex wrapper generated by Titrova (JSON to Apex).
 * Types are inferred from one sample payload. Review them before deploying.
 */
public class OrderResponse {
    public String orderId;
    public String status;
    public Decimal total;
    public Boolean paid;
    public Customer customer;
    public List<Line> lines;
    public List<String> tags;
    public Object coupon;

    public class Customer {
        public Integer id;
        public String name;
        public String email;
    }

    public class Line {
        public String sku;
        public Integer quantity;
        public Decimal unitPrice;
    }

    public static OrderResponse parse(String jsonString) {
        return (OrderResponse) JSON.deserialize(jsonString, OrderResponse.class);
    }
}

One thing to check

  • “coupon” is null in the sample, so its type is unknown. It was generated as Object — change it to the real type.

How to use the JSON to Apex Class Generator

  1. Paste a sample of the JSON you receive into the input, or drop a .json file onto it.
  2. Set the root class name. This becomes the outer Apex class, for example OrderResponse.
  3. Choose options: a parse() helper, @AuraEnabled for Lightning components, or { get; set; } properties.
  4. Select Generate Apex, then copy the code or download it as a .cls file.

What JSON to Apex conversion means

Apex is strongly typed. To read a JSON payload comfortably you need classes whose properties match the payload’s keys, so that JSON.deserialize can fill them in. Writing those classes by hand is slow and error-prone for anything beyond a few fields. A JSON to Apex converter reads a sample payload and writes the classes for you.

Why Salesforce developers need wrapper classes

  • REST callouts: parse the response of an external API into typed objects.
  • Apex REST services: deserialize a request body sent to your @RestResource class.
  • Lightning components: pass structured data between Apex and LWC with @AuraEnabled properties.
  • Platform events and webhooks: read JSON stored in a long text field.

Example

This JSON:

JSON
{
  "name": "Acme",
  "contacts": [
    { "email": "a@acme.example", "primary": true }
  ]
}

becomes this Apex:

Apex
public class AccountPayload {
    public String name;
    public List<Contact> contacts;

    public class Contact {
        public String email;
        public Boolean primary;
    }

    public static AccountPayload parse(String jsonString) {
        return (AccountPayload) JSON.deserialize(jsonString, AccountPayload.class);
    }
}

Common conversion problems

Reserved words

Keys such as class, limit, date, new and object cannot be Apex property names. The generator appends _x and, when the parse() option is on, adds one line per renamed key that rewrites the key in the JSON text before deserializing. The rewrite only matches a quoted name followed by a colon, so values are never touched.

Keys with hyphens, spaces or leading digits

first-name becomes first_name and 2fa becomes x2fa. Double underscores are collapsed because Apex reserves them. These are mapped by parse() in the same way.

Numbers that are too large for Integer

An Apex Integer holds 32 bits. Values above 2,147,483,647, such as timestamps in milliseconds, are generated as Long. If one array item has a decimal point, the whole property becomes Decimal.

Null and empty values

When the sample contains null or [], the real type is unknown, so the property is generated as Object or List<Object> and listed under “things to check”. Paste a sample where the value is filled in, or correct the type by hand.

Names that collide

Apex is case-insensitive, so Name and name in the same object would clash. The second one gets a numeric suffix and is mapped by parse().

Features and limitations

What it does

  • Nested objects become inner classes; arrays become List<T>, including arrays of arrays.
  • Numbers are typed as Integer, Long or Decimal from how they are written, so 1 and 1.0 differ.
  • Objects in an array are merged, so a key that appears in only some items is still included.
  • Reserved words and invalid names are renamed, and the generated parse() method maps them back.
  • Identical shapes share one class; different shapes with the same key get distinct names.
  • Clear error messages with the line and column of the first JSON syntax problem.

What it does not do

  • Types come from one sample. A null value or an empty array has no type to infer and becomes Object.
  • Dates are left as String. JSON has no date type and formats vary between APIs.
  • It does not create an Apex test class or deploy anything to your org.
  • Keys that depend on data, such as a map keyed by record ID, are generated as fixed properties. Use Map<String, Object> for those.
  • Generated code is checked against Apex naming rules, not compiled. Review it before deploying.

Questions about the JSON to Apex Class Generator

No. Parsing and code generation run in your browser. The JSON you paste is not sent to a server, logged or stored.

Deploy the class to your org, then call YourClass.parse(response.getBody()) after a callout. If you turned the parse() option off, call JSON.deserialize(body, YourClass.class) and cast the result.

It keeps a payload’s types together in one file, and it avoids name clashes with other classes in your org. Apex allows one level of inner classes, so every generated class sits directly inside the root class.

Yes. The root class describes one item, and parse() returns a List of the root class.

Turn on @AuraEnabled. Each property is annotated so the framework can serialize it when your Apex method returns the wrapper.

JSON.deserialize ignores them, so an API that adds new fields will not break your code. Properties that are missing from the payload are left as null.