dictutils.ops.deep_hasΒΆ

dictutils.ops.deep_has(obj, path)[source]ΒΆ

Check if a path exists in nested object.

Parameters:
  • obj (Any) – The object to check

  • path (Union[str, Sequence[Union[str, int]]]) – Path as string (β€œa.b.c”) or sequence [β€œa”, β€œb”, β€œc”]

Return type:

bool

Returns:

True if path exists, False otherwise

Example

>>> import json
>>> data = {"user": {"profile": {"name": "Alice"}}}
>>> result = deep_has(data, "user.profile.name")
>>> print(json.dumps(result, indent=4))
true
>>> result = deep_has(data, "user.profile.age")
>>> print(json.dumps(result, indent=4))
false