def get_path(self, json, path): """ traverses the dictionary derived from the json to look if it can satisfy the requested path :param json: :param path: :return: """ if (type(path) is str) or (type(path) is unicode): path = str(path).split('/') field = path.pop(0) try: if json.has_key(field): if type(json[field]) == dict: return self.get_path(json[field], path) elif type(json[field]) == list: if len(json[field]) < 2: Base.info("found %s" % (json[field][0])) return str(json[field][0]) elif len(path) == 0: Base.info("found %s using path %s" % (field, path)) return str(json[field]) else: Base.warning("the requested path of %s could not be found in the json document. returning None instead") return None except Exception: Base.error("Error encountered during resolution")
def get_path(self, json, path): """ traverses the dictionary derived from the json to look if it can satisfy the requested path :param json: :param path: :return: """ if (type(path) is str) or (type(path) is unicode): path = str(path).split('/') field = path.pop(0) try: if json.has_key(field): if type(json[field]) == dict: return self.get_path(json[field], path) elif type(json[field]) == list: if len(json[field]) < 2: Base.info("found %s" % (json[field][0])) return str(json[field][0]) elif len(path) == 0: Base.info("found %s using path %s" % (field, path)) return str(json[field]) else: Base.warning( "the requested path of %s could not be found in the json document. returning None instead" ) return None except Exception: Base.error("Error encountered during resolution")
def get_path(self, json, path): if (type(path) is str) or (type(path) is unicode): path = str(path).split('/') field = path.pop(0) try: if json.has_key(field): if type(json[field]) == dict: return self.get_path(json[field], path) elif type(json[field]) == list: if len(json[field]) < 2 : print "found %s" % (json[field][0]) return str(json[field][0]) elif len(path) == 0: print "found %s using path %s" % (field, path) return str(json[field]) else: print "the requested path of %s could not be found in the json document. returning None instead" return None except Exception: print "Error encountered during resolution"