For a given object, you can map the label back to the API field name with a describe call:
public static void setFieldValuesFromJson(sobjectType sourcesObject, sObject record, Map<String, Object> jsonMap) {
Map<String, sObjectField> fieldLabelToApiName = new Map<String, sObjectField>();
for(sObjectField field: sourcesObject.getDescribe().fields.getMap().values()) {
fieldLabelToApiName.put(field.getDescribe().getLabel(), field);
}
for(String key: jsonMap.keySet()) {
record.put(fieldLabelToApiName.get(key), jsonMap.get(key));
}
}
Where we use sObject.put(sObjectField field, Object value)
to place the values into the correct field. Since this is dynamic, be aware that changing the label or translating the field label may break this code.
You can call it using the following notation:
Exchange_Rate__c record = new Exchange_Rate__c(); // Or from a query...
Map<String, Object> jsonMap = (Map<String, Object>)JSON.deserializeUntyped(jsonBody);
setFieldValuesFromJson(Exchange_Rate__c.sobjectType, record, jsonMap);