Created
July 28, 2011 14:49
-
-
Save jed/1111672 to your computer and use it in GitHub Desktop.
JSON.stringify replacer that sorts object keys
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
replacer = (key, val) -> | |
if val instanceof Object | |
keys = Object.keys(val).sort().map (key) -> | |
"\"#{key}\":#{JSON.stringify val[key], replacer}" | |
"{#{keys}}" | |
else val |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ncr Thanks, that worked for me, but had to add a
null
check. In regular JS: