Integrating external systems with Salesforce is a common requirement, and often those systems communicate using JSON or XML. While Apex provides native tools to parse these formats, developers quickly run into limitations, especially as payload complexity grows.
In this blog, we’ll explore:

Apex provides built-in classes like JSON.deserialize() and JSONParser for handling JSON.
{
"name": "Mahesh Raja",
"age": 30,
"isActive": true
}
public class Customer {
public String name;
public Integer age;
public Boolean isActive;
}
String jsonString = '{"name":"Mahesh Raja","age":30,"isActive":true}';
Customer cust = (Customer) JSON.deserialize(jsonString, Customer.class);
System.debug(cust.name); // Mahesh Raja
String jsonString = '{"name":"Mahesh Raja","age":30}';
Map<String, Object> result = (Map<String, Object>) JSON.deserializeUntyped(jsonString);
System.debug(result.get('name'));
XML parsing is handled via the Dom.Document class.
<customer>
<name>John Doe</name>
<age>30</age>
</customer>
String xmlString = '<customer><name>John Doe</name><age>30</age></customer>';
Dom.Document doc = new Dom.Document();
doc.load(xmlString);
Dom.XmlNode root = doc.getRootElement();
String name = root.getChildElement('name', null).getText();
String age = root.getChildElement('age', null).getText();
System.debug(name);
While the above methods work well for simple payloads, real-world integrations introduce several complications:
JSON and XML payloads can be highly nested.
External APIs evolve frequently.
APIs may return:
Handling this in Apex:
if(result.containsKey('data')) {
// defensive coding everywhere
}
Often, parsing is just step one. You also need to:
This leads to:
Apex is designed for business logic—not for complex data transformation.
When used for parsing + mapping + transformation:
Parsing JSON and XML in Apex works well for simple and predictable integrations. However, as payloads become more complex, dynamic, and deeply nested, the limitations of traditional approaches become increasingly evident. What starts as straightforward parsing can quickly turn into verbose, tightly coupled, and hard-to-maintain code.
The core challenge lies in using a language designed for business logic to handle heavy data transformation. This leads to mixed concerns, reduced readability, and slower adaptability when external systems evolve.
To build scalable, resilient, and future-ready integrations, it’s important to rethink how we approach data transformation in Salesforce.
In our next blog, we’ll introduce a powerful new concept – DataWeave – and explore how it simplifies complex transformations while bringing clarity, flexibility, and efficiency to your integration design.