Created
June 27, 2016 22:09
-
-
Save dmi3y/57533ef09eed5fc5ebd8c088e098ca1a to your computer and use it in GitHub Desktop.
Sort JSON structure by keys recursevely
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 sortJsonByKeys (json) { | |
let out = {} | |
let keys = Object.keys(json) | |
keys.sort() | |
keys.forEach((key) => { | |
if (typeof json[key] === 'object') { | |
out[key] = sortJsonByKeys(json[key]) | |
} else { | |
out[key] = json[key] | |
} | |
}) | |
return out | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment