def to_json(object):
    """
    Return a JSON serialization of an object.
    Standard types (None, bool, int, float, str, etc.) are using
    json.dumps whereas other type of object must define a to_json
    method returning the serialization.
    """
    serializer = getattr(object, 'to_json', None)
    if serializer is None:
        if object is None:
            return None
        raise ValueError('Cannot serialize in JSON object of type {0}'.
            format(type(object)))
    else:
        return serializer()
