Skip to main content
SFDC Developers

JSON to Apex Class Generator

Paste any JSON payload and instantly generate Salesforce Apex wrapper classes with smart type detection, nested class support, a parse() method, and a matching test class — all processed in your browser with no data sent to our servers.

JSON Input
Paste JSON on the left and click
"Generate Apex Classes" to see output here.

Frequently Asked Questions

How do I parse JSON in Salesforce Apex?

The recommended approach is to create a wrapper class that mirrors the JSON structure, then call JSON.deserialize(jsonString, WrapperClass.class). This tool generates that wrapper class automatically from your JSON payload, including proper type mapping and a ready-to-use parse() method. For dynamic or unknown JSON structures, you can use JSON.deserializeUntyped() which returns Map<String, Object>, but you lose compile-time type safety.

What is JSON.deserialize() in Apex?

JSON.deserialize() is a built-in Apex method that converts a JSON string into a typed Apex object. It requires a target class whose fields match the JSON keys. Unlike JSON.deserializeUntyped() which returns generic Map<String, Object>, deserialize() gives you compile-time type safety, IntelliSense support in VS Code, and cleaner code. The JSON keys must match the Apex field names (case-insensitive).

How does the type detection work?

The tool analyzes each JSON value to determine the best Apex type. Integers map to Integer (or Long if they exceed 2^31). Decimals become Decimal. Booleans become Boolean. Strings are checked against ISO date patterns — "2024-01-15" becomes Date and "2024-01-15T10:30:00Z" becomes Datetime. Arrays become List<T> with the element type inferred from all items. Mixed-type arrays widen to the common supertype (e.g., Integer + Decimal = Decimal).

What happens with nested JSON objects?

Nested objects are converted to Apex classes. You can choose between inner classes (nested inside the root class) or separate top-level classes. Inner classes are cleaner for simple structures and keep everything in one file. Separate classes are better when you need to reuse them across multiple Apex classes or when the nesting gets deep.

Does it handle Apex reserved words?

Yes. If a JSON key matches an Apex reserved word like class, delete, or switch, the generated field name gets an _x suffix (e.g., class_x). Keys starting with digits are prefixed with x_. JSON keys in snake_case or kebab-case are automatically converted to Apex camelCase convention.

Is my JSON data sent to your server?

No. All parsing and code generation happens entirely in your browser using JavaScript. No JSON data, generated Apex code, or any other input leaves your machine. You can verify this by using the tool with your browser's network tab open — no requests are made.

Related Salesforce Developer Tools

  • SOQL Query Builder

    Build SOQL queries visually after generating your wrapper classes — select objects, pick fields, and copy queries.

  • Apex Debug Log Analyzer

    Debug your integration code by analyzing Apex logs — see callout times, JSON parsing overhead, and governor limits.

  • Schema ERD Viewer

    Visualize the Salesforce objects your wrapper classes map to — see relationships and field types.

Trending Now