<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 organizations using Sorting Hat format. The Sorting Hat organizations format is a JSON stream which its keys are the name of the organizations. Each organization object has a list of domains. For instance: { "organizations": { "Bitergia": [ { "domain": "api.bitergia.com", "is_top": false }, { "domain": "bitergia.com", "is_top": true } ], "Example": [] }, "time": "2015-01-20 20:10:56.133378" } :param json: stream to parse :raises InvalidFormatError: raised when the format of the stream is not valid. """

        try:
            for organization in json['organizations']:
                name = self.__encode(organization)

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

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

                domains = json['organizations'][organization]

                for domain in domains:
                    if type(domain['is_top']) != bool:
                        msg = "invalid json format. 'is_top' must have a bool value"
                        raise InvalidFormatError(cause=msg)

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