def to_json(self):
        """
        Encodes a Collection as a json representation so it can be sent through the bitmessage network
        :return: the json representation of the given Collection
        """
        json_docs = []
        for doc in self.documents:
            json_docs.append({"address": doc.collection_address, "description": doc.description, "title": doc.title,
                              "hash": doc.hash, "filename": doc.filename, "accesses": doc.accesses})

        json_keywords = []
        for key in self.keywords:
            json_keywords.append({"id": key.id, "name": key.name})
        json_representation = {"type_id": 1,
                               "title": self.title,
                               "description": self.description,
                               "keywords": json_keywords,
                               "address": self.address,
                               "documents": json_docs,
                               "btc": self.btc,
                               "latest_broadcast_date": self.latest_broadcast_date.strftime("%A, %d. %B %Y %I:%M%p"),
                               "creation_date": self.creation_date.strftime("%A, %d. %B %Y %I:%M%p"),
                               "oldest_date": self.oldest_date.strftime("%A, %d. %B %Y %I:%M%p"),
                               "latest_btc_tx": self.latest_btc_tx,
                               "oldest_btc_tx": self.oldest_btc_tx,
                               "accesses": self.accesses,
                               "votes": self.votes,
                               "votes_last_checked": self.votes_last_checked.strftime("%A, %d. %B %Y %I:%M%p")}
        try:
            validate(json_representation, coll_schema)
            return json.dumps(json_representation, sort_keys=True)
        except ValidationError as m:
            return None