Skip to content

Instantly share code, notes, and snippets.

@lsmith
Created October 14, 2009 05:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lsmith/209826 to your computer and use it in GitHub Desktop.
Save lsmith/209826 to your computer and use it in GitHub Desktop.
JSON.stringify(o, function (k,v) {
if (v && typeof v === 'object' && !isArray(v)) { // assumes an isArray function
var sorted = {},
keys = [],
key,i,len;
for (key in v) {
if (v.hasOwnProperty(key)) {
keys.push(key);
}
}
keys.sort();
for (i = 0, len = keys.length; i < len; ++i) {
sorted[keys[i]] = v[keys[i]];
}
return sorted;
} else {
return v;
}
}, 4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment