Skip to content

Instantly share code, notes, and snippets.

@bobzoller
Created October 25, 2018 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobzoller/9e982942d77572c04280e9f5de4bd468 to your computer and use it in GitHub Desktop.
Save bobzoller/9e982942d77572c04280e9f5de4bd468 to your computer and use it in GitHub Desktop.
function downcaseJSONKeys(obj) {
if (!obj) {
return;
}
if (typeof obj !== 'Object' && typeof obj !== 'object') {
return;
}
var keys = Object.keys(obj);
var result = {};
keys.map(function(k, v) {
if (typeof k === 'string') {
if (typeof obj[k] === 'string') {
result[k.toLowerCase()] = obj[k].toLowerCase();
} else {
// if the node is an object, perform the same process over that node
if (typeof obj[k] === 'Object' || typeof obj[k] === 'object') {
result[k.toLowerCase()] = downcaseJSONKeys(obj[k]);
} else {
result[k.toLowerCase()] = obj[k];
}
}
}
});
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment