Created
October 25, 2018 01:12
-
-
Save bobzoller/9e982942d77572c04280e9f5de4bd468 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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