Skip to content

Instantly share code, notes, and snippets.

@dac09
Created September 10, 2014 00:01
Show Gist options
  • Save dac09/6985086746dabb083e9a to your computer and use it in GitHub Desktop.
Save dac09/6985086746dabb083e9a to your computer and use it in GitHub Desktop.
Recursively convert object keys from CapitalCase to camelCase
function camelCase(input) {
return input.charAt(0).toLowerCase() + input.slice(1);
}
function allCapitalCasetoCamelCase(obj) {
var output = {};
for (i in obj) {
if ((Object.prototype.toString.apply(obj[i]) === '[object Object]') || (Object.prototype.toString.apply(obj[i]) === '[object Array]') ) {
output[camelCase(i)] = allCapitalCasetoCamelCase(obj[i]);
} else {
output[camelCase(i)] = obj[i];
}
}
return output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment