function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Admin User 1137Admin User 1137 

How to deserialize the below mentioned json format from Mule in Apex Salesforce ?


How to deserialize the below mentioned json format from Mule in Apex Salesforce ?

Could any one help me out with this ?

{  
    SalesDetails=    [  
        {           
            "getVO":{  
                "Delivery_Date__c":" test";
                "Salesman_Name__c":"test",
                "Deal_Number__c":"test",
                "Worksheet_Total__c":"test",
                "Selling_Dealer__C":"test",
                "Name":"UNREG",
                "ContactName__c":"test"
            },
            "getVehicle":{  
                "Stock_No__c":"test",
                "Name":"test",
                "Engine_Number__c":"test",
                "Rego_Number__c":"test",
                "Make__c":"test",
                "Model_Name__c":"test",
                "Model_Description__c":"test",
                "Colour__c":"test",
                "Vehicle_Type__c":"test"
            },
            "getAccount":{  
                "Customer_ID__c":"test",
                "First_Name__c":"test",
                "Last_Name__c":"test",
                "Salutation__c":"test",
                "Business_Email__c":"test",
                "Home_Email__c":"test",
                "Date_of_Birth__c":test",
                "License_Number__c":"test",
                "Preferred_Name__c":"test",
                "License_Expiry_Date__c":test",
                "Selling_Dealer__c":"test",
                "Contact_Type__c":"test",
                "Name":"test",
                "Business_Phone__c":"test",
                "Business_Phone_Valid__c":true,
                "Phone1__c":"test",
                "Phone1_Valid__c":true,
                "Home_Phone__c":"",
                "Home_Phone_Valid__c":false,
                "Mobile__c":"test",
                "Mobile_Phone_Valid__c":true,
                "Business_Email_Valid__c":true,
                "Home_Email_Valid__c":true,
                "Physical_Latitude__c":"test",
                "Physical_Longitude__c":"test",
                "Physical_Address__c":"test",
                "Physical_Address_Valid__c":true,
                "PhysicalDPID__c":"test",
                "Physical_Suburb__c":"test",
                "Physical_State__c":"test",
                "Physical_Post_Code__c":"test",
                "Eranet_Data_Time__c":test,
                "Id":"test",
                "Old_Customer_Id__c":"test",
                "Physical_Country__c":"test"
            },
            "getContact":{  
                "Customer_ID__c":"test",
                "Salutation":"test",
                "Preferred_Name__c":"test",
                "FirstName":"test",
                "LastName":"test",
                "Business_Email__c":"test",
                "Home_Email__c":"test",
                "Date_of_Birth__c":test,
                "License_Number__c":"test",
                "License_Expiry_Date__c":test,
                "Selling_Dealer__c":"test",
                "Business_Phone__c":"test",
                "Business_Phone_Valid__c":test,
                "Phone1__c":"test",
                "Phone1_Valid__c":true,
                "HomePhone":"",
                "Home_Phone_Valid__c":false,
                "MobilePhone":"test",
                "Mobile_Phone_Valid__c":true,
                "Business_Email_Valid__c":true,
                "Home_Email_Valid__c":true,
                "Physical_Latitude__c":"test",
                "Physical_Longitude__c":"test",
                "Physical_Address__c":"test",
                "Physical_Address_Valid__c":true,
                "PhysicalDPID__c":"test",
                "Physical_Suburb__c":"test",
                "Physical_State__c":"test",
                "Physical_Post_Code__c":"test",
                "Eranet_Data_Time__c":test,
                "AccountId":"test",
                "Id":"test",
                "Old_Customer_Id__c":"test",
                "Physical_Country__c":"test"
            }
            "getLead":{
                "Id": "",
                "Type": "test",
                "AccountId":"",
                "ContactID":"",
                "OppurtunityFlag": "Yes"
            },
            "getOpportunityFields":{
                "AccountId": "",
                "AccountName": "",
                "VehicleId": "",
                "Model__c":"",
                "Make__c": "",
                "Selling_Dealership__c": "",
                "Request_Type__c": "",
                "Enrolled_Date__c": "",
                "LeadSource": "",
                "CampaignId": "",
                "OpportunityName": "",
                "OpportunityOwner": "",
                "OpportunityStage": "Won",
                "Closeddate": "",
                "Status":"",
                "Price__c": ""
            },
            "getlstLiveCampaignMemberId":
            [
                {
                    "LiveCMID": "test",
                    "Status": "test"
                }
            ],
            "getlstPrimaryCampaignMemberId":
            [
                {
                    "PrimaryCMID": "test",
                    "Status":"Closed"
                }
            ]
        }
    ],
    TransactionId=dfd62371-766b-11e6-87eb-b82a72a03108
}
 
karthikeyan perumalkarthikeyan perumal
Hello, 

Below is the sample code but not exact code, 

replace jsonInput with above mule JSON string. make same formate. and try 
 
String jsonInput = '{\n' +
    ' "description" :"An appliance",\n' +
    ' "accessories" : [ "powerCord", ' + 
      '{ "right":"door handle1", ' + 
        '"left":"door handle2" } ],\n' +
    ' "dimensions" : ' + 
      '{ "height" : 5.5 , ' + 
        '"width" : 3.0 , ' + 
        '"depth" : 2.2 },\n' +
    ' "type" : null,\n' +
    ' "inventory" : 2000,\n' +
    ' "price" : 1023.45,\n' +
    ' "isShipped" : true,\n' +
    ' "modelNumber" : "123"\n' +
    '}';
    
Map<String, Object> m = 
   (Map<String, Object>)
      JSON.deserializeUntyped(jsonInput);

System.assertEquals(
   'An appliance', m.get('description'));
        
List<Object> a = 
   (List<Object>)m.get('accessories');
System.assertEquals('powerCord', a[0]);        
Map<String, Object> a2 = 
   (Map<String, Object>)a[1];

Hope this will help you, 

Thanks
karthik