def convertResponseToJson(self, jsonCandidate):
        try:
            def raiseException():
                guid = uuid.uuid4()

                logging.error("%s of type %s is not valid json. guid = %s", jsonCandidate, type(jsonCandidate), guid)
                raise Exceptions.SubscribableWebObjectsException("result was not valid json. Guid = %s" % guid)

            if jsonCandidate is None:
                return jsonCandidate

            if isinstance(jsonCandidate, (int,str,unicode,float,bool,long)):
                return jsonCandidate

            if isinstance(jsonCandidate, (list, tuple)):
                return [self.convertResponseToJson(r) for r in jsonCandidate]

            if isinstance(jsonCandidate, dict):
                newDict = {}
                for k,v in jsonCandidate.iteritems():
                    if not isinstance(k,str):
                        raiseException()
                    newDict[k] = self.convertResponseToJson(v)

                return newDict

            objDefPopulated = False
            try:
                if ComputedGraph.isLocation(jsonCandidate):
                    if jsonCandidate in self.objectToIdCache_:
                        objDef = {
                            'objectId_': self.lookupObjectId(jsonCandidate)
                            }
                    else:
                        objDef = {
                            "objectId_": self.lookupObjectId(jsonCandidate),
                            "objectDefinition_": {
                                'type': AllObjectClassesToExpose.typenameFromType(
                                    ComputedGraph.getLocationTypeFromLocation(jsonCandidate)
                                    ),
                                'args': jsonCandidate.__reduce__()[1][0]
                                }
                            }
                    objDefPopulated = True
                else:
                    objDef = jsonCandidate.objectDefinition_
                    objDefPopulated = True
            except AttributeError:
                objDefPopulated = False

            if objDefPopulated:
                return self.convertResponseToJson(objDef)

            raiseException()
        except:
            logging.error("%s of type %s is not valid json.", jsonCandidate, type(jsonCandidate))
            raise
dataset/ETHPy150Open ufora/ufora/ufora/BackendGateway/SubscribableWebObjects/MessageProcessor.py/OutgoingObjectCache.convertResponseToJson/original