Skip to content

Instantly share code, notes, and snippets.

@muratpurc
Created May 26, 2014 21:40
Show Gist options
  • Save muratpurc/fa9741e30163b3e0c936 to your computer and use it in GitHub Desktop.
Save muratpurc/fa9741e30163b3e0c936 to your computer and use it in GitHub Desktop.
JS: JSON.stringify
// Helper function to convert JSON to it's string representation
var jsonStringify = typeof JSON !== 'undefined' ? JSON.stringify : function(obj) {
var arr = [];
$.each(obj, function(key, val) {
var next = key + ': ';
next += (val === Object(val)) ? jsonStringify(val) : val;
arr.push(next);
});
return '{ ' + arr.join(', ') + ' }';
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment