Build Keymap, then Apply, with UnderscoreJS
http://stackoverflow.com/questions/8747561/is-there-any-way-to-rename-js-object-keys-using-underscore-js/23375951#23375951
for more details.
HTML
<script src="http://documentcloud.github.com/underscore/underscore.js"></script>
JavaScript
var a = {
name : "Foo",
amount: 55,
reported : false,
date : "10/01/2001"
};
function capitalize(string)
{
return string.charAt(0).toUpperCase() + string.slice(1);
}
var b = {};
var map = {
name : "id",
amount : "total",
reported : "updated",
date : "issued"
};
var keymap = {};
_.each(a, function(value, key) {
var oldkey = key;
key = capitalize(key);
keymap[oldkey] = key;
});
_.each(a, function(value, key) {
key = keymap[key] || key;
b[key] = value;
});
console.log(b);