Created
April 16, 2015 09:25
-
-
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.
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
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