Skip to content

Instantly share code, notes, and snippets.

@dmi3y
Created June 27, 2016 22:09
Show Gist options
  • Save dmi3y/57533ef09eed5fc5ebd8c088e098ca1a to your computer and use it in GitHub Desktop.
Save dmi3y/57533ef09eed5fc5ebd8c088e098ca1a to your computer and use it in GitHub Desktop.
Sort JSON structure by keys recursevely
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