function error2json( err ) {
	var keys;
	var out;
	var i;
	if ( !isError( err ) ) {
		throw new TypeError( format( 'invalid argument. Must provide an error object. Value: `%s`.', err ) );
	}
	out = {};

	// Guaranteed properties:
	out.type = typeName( err );
	out.message = err.message;

	// Possible general error properties...
	if ( err.name ) {
		out.name = err.name;
	}
	if ( err.stack ) {
		out.stack = err.stack;
	}
	// Possible Node.js (system error) properties...
	if ( err.code ) {
		out.code = err.code;
	}
	if ( err.errno ) {
		out.errno = err.errno;
	}
	if ( err.syscall ) {
		out.syscall = err.syscall;
	}
	// Any enumerable properties...
	keys = objectKeys( err );
	for ( i = 0; i < keys.length; i++ ) {
		out[ keys[i] ] = copy( err[ keys[i] ] );
	}
	return out;
}
Returns a JSON representation of an error object.

@param {(Error|TypeError|SyntaxError|URIError|ReferenceError|RangeError|EvalError)} err - error to serialize
@throws {TypeError} must provide an error object
@returns {Object} JSON representation

@example
var err = new Error( 'beep' );
var json = error2json( err );
// returns {...}