I’m trying to map a nested JSON response from an external REST API to Architect variables in a Data Action. The API call succeeds with a 200, but the variable assignment fails silently. Here’s the mapping config I’m using:
{
"variableName": "customerName",
"dataSource": "response.body",
"path": "data.profile.name"
}
The actual response looks like this:
{
"status": "ok",
"data": {
"profile": {
"name": "John Doe"
}
}
}
Am I missing something with the path syntax?
The silent failure usually hits when the path string doesn’t exactly match the JSON structure. Architect’s mapping is strict. If data.profile.name isn’t a leaf node, it won’t bind. Try logging the raw body to a string variable first. Then parse it in a subsequent step to verify the actual key names.
1 Like
Cause: Architect’s built-in JSON path parser doesn’t handle nested objects reliably when the response body is treated as a raw string, or if the JSON structure has dynamic keys. The silent failure occurs because the mapping engine can’t resolve data.profile.name if data is an array or if profile is null. Also, Architect variables are string-based, so attempting to map a complex JSON object to a single variable will not work; you need to flatten the structure.
Solution: Avoid relying on the visual mapper for complex JSON responses. use a Data Action with JavaScript to parse the response and set specific string values. This approach provides cleaner code and allows for solid error handling.
Create a Data Action containing a Parse JSON step to process the API response. Then, use a Set Variable step to assign the desired values.
// Data Action Script: Parse JSON
// Assuming the API call is already made and the response is in $request.body
// Check if the path exists to avoid null errors
var name = "";
if ($request.body.data && $request.body.data.profile) {
name = $request.body.data.profile.name;
}
// Set the Architect variable
$context.customerName = name;
This approach bypasses the mapper’s limitations, offering full control over null checks. If the API returns a list, you can iterate through it using JavaScript loops. If a single object, you can extract the exact field. This eliminates silent failures.
One consideration: ensure your API request within the Data Action is configured correctly, including any necessary authentication headers. Also, verify the response content type. If it’s not application/json, the JSON.parse() function will fail. Implement a try...catch block to handle potential parsing errors, especially when interacting with potentially unreliable APIs.
try {
var parsedJson = JSON.parse($request.body);
// ... further parsing and variable assignment ...
} catch (error) {
Log("Parse error: " + error.message);
$context.customerName = "Unknown";
}
This ensures a more stable and predictable flow.
1 Like