woob.browser.filters.json

class Dict(selector=None, default=_NO_DEFAULT)[source]

Bases: Filter

Filter to find elements in a dictionary or list.

Note that a selector defined as None or an empty string will be equivalent to selecting the root of the provided document, as for None.

Parameters:
  • selector (str | _Filter | Callable | Any | None) – Input selector to use on the object. (default: None)

  • default (Any) – Default value is an element of the chain is not found, or (default: _NO_DEFAULT) if a type mismatch occurs.

>>> d = {'a': {'b': 'c', 'd': None}}
>>> Dict('')(d)
{'a': {'b': 'c', 'd': None}}
>>> Dict()(d)
{'a': {'b': 'c', 'd': None}}
>>> Dict('a/b')(d)
'c'
>>> Dict('a')(d)
{'b': 'c', 'd': None}
>>> Dict('notfound')(d)
Traceback (most recent call last):
    ...
woob.browser.filters.base.ItemNotFound: Element ['notfound'] not found
>>> Dict('notfound', default=None)(d)
>>>
filter(value)[source]

This method has to be overridden by children classes.

classmethod select(selector, item, obj=None, key=None)[source]