I am expecting two separate jsons in case of success and failure. In case of success I get a nested json whereas in failure I get a simple json mentioning status : failed so my class I used to handle success is failing for failure scenario. Can someone please guide here? Only way I can think in checking the substring of json and validate before parsing but that doesn't seem a good solution. Updated Jsons: **Success:** { "Subscriptions": [ { "Subscription": { "SAPOrder": "SAP123", "RequestType": "New", "OrderStatus": "0", "Services": [ { "Service": [{ { "attribute": { "name": "Resilience", "value": "Terminated" } }, { "attribute": { "name": "Number", "value": "1234" } }, { "attribute": { "name": "serviceStartDate", "value": "2018-08-220T02:13:20" } } }, {{ "attribute": { "name": "Resilience", "value": "Terminated" } }, { "attribute": { "name": "Number", "value": "1234" } }, { "attribute": { "name": "serviceStartDate", "value": "2018-08-220T02:13:20" } } } ] } ] } } ] } **Failure:** { "Subscriptions": [ { "Subscription": { "SAPOrder": "SAP123", "RequestType": "New", "OrderStatus": "Failed" } } **Added Class details:** public class JSON2Apex { public class Services { public List<Service> Service; } public List<Subscriptions> Subscriptions; public class Attribute { public String name; public String value; } public class Subscriptions { public Subscription Subscription; } public class Service { public List<Attribute> attribute; } public class Subscription { public String SAPOrder; public String RequestType; public String OrderStatus; public List<Services> Services; } public static JSON2Apex parse(String json) { return (JSON2Apex) System.JSON.deserialize(json, JSON2Apex.class); } }