Created
September 9, 2014 11:34
-
-
Save hogedigo/b676a86b423ca7314250 to your computer and use it in GitHub Desktop.
sorting keys in JSON
This file contains 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
var json = JSON.stringify(data, function(key, value) { | |
if (value instanceof Object === false || Object.getPrototypeOf(value) !== Object.prototype) { | |
return value; | |
} | |
var keys = Object.keys(value); | |
keys.sort(); | |
var newValue = {}; | |
keys.forEach(function(key) { | |
newValue[key] = value[key]; | |
}); | |
return newValue; | |
}, 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment