Answers for "python dict multiple level jsonpath"

0

python dict multiple level jsonpath

class DictQuery(dict):
    def get(self, path, default = None):
        keys = path.split("/")
        val = None

        for key in keys:
            if val:
                if isinstance(val, list):
                    val = [ v.get(key, default) if v else None for v in val]
                else:
                    val = val.get(key, default)
            else:
                val = dict.get(self, key, default)

            if not val:
                break;

        return val
Posted by: Guest on August-25-2020

Python Answers by Framework

Browse Popular Code Answers by Language