Frequently Asked Questions (FAQ)

What is a JSON to Apex Converter and why do Salesforce developers need it?
A JSON to Apex converter is a utility that parses a JSON (JavaScript Object Notation) payload and automatically generates the corresponding Salesforce Apex wrapper class. When developing API integrations, Salesforce Apex requires strongly typed variables to deserialize and work with incoming JSON payloads. Writing these wrapper classes manually (especially for large, nested JSON structures) is tedious, repetitive, and prone to formatting errors. This tool automates the creation of clean, robust Apex class structures and companion test classes, saving developers hours of manual coding.
How does json2apex map JSON data types to Apex data types?
Our generator analyzes the structure and values of your JSON input to apply type-safe mappings:
  • Strings: Mapped directly to String.
  • Numbers (Integers): If a numeric value has no decimal part, it maps to Integer.
  • Numbers (Decimals): If a numeric value contains a decimal portion, it maps to Decimal to preserve mathematical precision.
  • Booleans: Mapped to Boolean.
  • Nulls: Defaults to Object since the exact type cannot be inferred from a null value.
  • Objects: Converted into a nested public class inside the wrapper, or maps to a generic Map<String, Object> if it represents a dynamic dictionary.
  • Arrays/Lists: Mapped to List<T>, where T is the inferred type of the array elements.
How does the tool handle Salesforce reserved keywords in JSON keys?
Salesforce Apex has reserved keywords like class, public, private, currency, object, char, etc. If your incoming JSON has a key that is a reserved keyword (e.g., "class": "Premium"), Apex will throw a syntax compilation error if you try to declare public String class;. To solve this, json2apex automatically sanitizes keys by prepending them with a leading underscore (e.g., _class).

Pro-Tip: To deserialize these fields correctly in Salesforce, you can either perform a string replacement of the reserved keys before deserializing (e.g., jsonString.replace('"class":', '"_class":')) or use Apex's native System.JSON.deserializeUntyped() to parse the payload dynamically.
What is the difference between typed deserialization and untyped deserialization in Apex?
  • Typed Deserialization: Uses System.JSON.deserialize(jsonString, ApexClassName.class). It compiles the JSON payload directly into an instance of your Apex wrapper class. This is type-safe, easy to read, and provides autocomplete support in your IDE.
  • Untyped Deserialization: Uses System.JSON.deserializeUntyped(jsonString). This parses the JSON into a generic Map<String, Object>. It is highly flexible and useful for handling dynamic JSON keys or schemas that change frequently, but it requires manual type casting (e.g., (String)myMap.get('name')) and does not compile-time validate the fields.
How do I handle dynamic or unpredictable JSON keys in Apex wrapper classes?
If your JSON payloads contain unpredictable keys (such as user IDs or product codes as top-level keys, e.g. {"12345": {"name": "Product A"}}), static wrapper properties will fail to compile. In these scenarios, you should parse the payload using JSON.deserializeUntyped(). You can then cast the result to Map<String, Object> and iterate over the keys dynamically using the map's keySet() method.
Does the converter generate unit test classes? How do I write HTTP mock callouts?
Yes! json2apex generates both the class structure and a corresponding @isTest unit test class. The generated test class sets up the JSON mock string, invokes the deserializer, and asserts that the parsed wrapper instance is not null.

To mock HTTP responses for integrations in your tests, implement the HttpCalloutMock interface. In your mock class, you can instantiate the wrapper, populate it with test data, and serialize it back to JSON using JSON.serialize(wrapperObj) to form the HTTP response body.
Is my JSON data secure when using json2apex.com?
Absolutely. Your privacy and security are our highest priorities. All JSON validation, parsing, and Apex code generation take place entirely client-side in your local web browser using JavaScript. No JSON inputs or generated Apex classes are sent to our servers, nor do we store any integration payloads on our database. You can even run this website fully offline.