+ Start a Discussion
Jay MandalJay Mandal 

How Convert JSON to sobject if JSON has extra attribute

Hello everyone,
I am sending json from lwc to controller without extra attribute in Account and contact object, in apex controller I want to parse it back to Account and Contact object by removing extra attribute in json.
Below is the json and class I am calling with same json. But it is giving error for extra attribute in JSON, can anyone help how we can parse back to Account and contact safely.

String json={
"account":{
Applied_Autocharges__c: 0
Name:"Test Account"
CLM_Value__c: 0
Id: "a0F6s000001MozYEAS"
Is_Estimated__c: false
Reason_Code__c: "11-Product Rejected & Reconsigned"
isEdit: true
isAllowed: true
priceReadOnly: false
productId: "a056s0000018MjrAAE"
},
"contact"{
LastName="Teast Contact"
Id: "a0F6s000001MozYEAS"
Is_Estimated__c: false
Reason_Code__c: "11-Product Rejected & Reconsigned"
isEdit: true
isAllowed: true
priceReadOnly: false
productId: "a056s0000018MjrAAE"
},


}

@AuraEnabled 
public stativc void updaeData(String json){
DataWrapper data=(DataWrapper)JSON.desearilize(json,DataWrapper.class);

}
Public class DataWrapper(){
public Account account;
public Contact contact;
}

Thanks,
Jay