Skip to content

Instantly share code, notes, and snippets.

@FLamparski
Created April 16, 2015 09:25
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 FLamparski/072f43cab3bab669c016 to your computer and use it in GitHub Desktop.
Save FLamparski/072f43cab3bab669c016 to your computer and use it in GitHub Desktop.
A function to serialise an object to JSON which also tries to pull in non-enumerable properties. Example usage: turning exceptions to JSON.
function serialiseAll(object) {
var properties = Object.getOwnPropertyNames(object);
var plainObject = _.reduce(properties, function(obj, prop) {
obj[prop] = object[prop];
return obj;
}, {});
return JSON.stringify(plainObject);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment