Function for accessing and searching dictionaries using /slashed/paths (like xpath)
I would skip the [] in the path.  Just presume val is a dict with strings for keys (the usual case).  It that doesn't work, try converting the key to an int.
def dict_query(d: Dict, path: str) -&gt; Union[object, None]:
    &quot;&quot;&quot;
    # Example usage:
    &gt;&gt;&gt; d = {'a': [{}, {'b': 9}]}
    &gt;&gt;&gt; print( dict_query(d, 'a/1/b') )
    9
    &quot;&quot;&quot;
    keys = path.split(&quot;/&quot;)
    val = d

    try:
        for key in keys:
            try:
                val = val[key]
                
            except (KeyError, TypeError):
                val = val[int(key)]
        
        return val
    
    except (IndexError, KeyError, TypeError, ValueError):
        return None