<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def __parse_organizations(self, json):
 """Parse Stackalytics organizations. The Stackalytics organizations format is a JSON document stored under the "companies" key. The next JSON shows the structure of the document: { "companies" : [ { "domains": ["alcatel-lucent.com"], "company_name": "Alcatel-Lucent", "aliases": ["Alcatel Lucent", "Alcatel-Lcuent"] }, { "domains": ["allegrogroup.com", "allegro.pl"], "company_name": "Allegro", "aliases": ["Allegro Group", "Grupa Allegro", "Grupa Allegro Sp. z o.o."] }, { "domains": ["altiscale.com"], "company_name": "Altiscale" }, ] } :param json: JSON object to parse :raises InvalidFormatError: raised when the format of the JSON is not valid. """

        try:
            for company in json['companies']:
                name = self.__encode(company['company_name'])

                org = self._organizations.get(name, None)

                if not org:
                    org = Organization(name=name)
                    self._organizations[name] = org

                for domain in company['domains']:
                    if not domain:
                        continue
                    dom = Domain(domain=domain)
                    org.domains.append(dom)
        except KeyError as e:
            msg = "invalid json format. Attribute %s not found" % e.args
            raise InvalidFormatError(cause=msg)