<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def export(self, source=None):
 """Export a set of unique identities. Method to export unique identities from the registry. Identities schema will follow Sorting Hat JSON format. When source parameter is given, only those unique identities which have one or more identities from the given source will be exported. :param source: source of the identities to export :returns: a JSON formatted str """

        uidentities = {}

        uids = api.unique_identities(self.db, source=source)

        for uid in uids:
            enrollments = [rol.to_dict()
                           for rol in api.enrollments(self.db, uuid=uid.uuid)]

            u = uid.to_dict()
            u['identities'].sort(key=lambda x: x['id'])

            uidentities[uid.uuid] = u
            uidentities[uid.uuid]['enrollments'] = enrollments

        blacklist = [mb.excluded for mb in api.blacklist(self.db)]

        obj = {'time': str(datetime.datetime.now()),
               'source': source,
               'blacklist': blacklist,
               'organizations': {},
               'uidentities': uidentities}

        return json.dumps(obj, default=self._json_encoder,
                          indent=4, separators=(',', ': '),
                          sort_keys=True)