Skip to content

Instantly share code, notes, and snippets.

@bogdanbiv
Created October 12, 2014 18:28
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 bogdanbiv/315c11e8f764f16c4552 to your computer and use it in GitHub Desktop.
Save bogdanbiv/315c11e8f764f16c4552 to your computer and use it in GitHub Desktop.
Serialize object keys and values except values that are arrays or other objects. This is to be used in case JSON.stringify fails due to cyclic...
function mystringify(input) {
var key, type, retVal = "";
for(key in input) {
if (input.hasOwnProperty(key)) {
type = typeof(input[key]);
if (type === 'array' || type === 'object') {
retVal += key + ": " + type + ", ";
} else {
retVal += key + ": " + input[key] + ", ";
}
}
}
return retVal;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment