MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / json_path_get

Function json_path_get

sdks/python/tests/test_contract.py:51–69  ·  view source on GitHub ↗

Evaluate a simple JSON path like 'agents[0].email' or 'agents.length'.

(obj: Any, path: str)

Source from the content-addressed store, hash-verified

49
50
51def json_path_get(obj: Any, path: str) -> Any:
52 """Evaluate a simple JSON path like 'agents[0].email' or 'agents.length'."""
53 parts = path.split(".")
54 current = obj
55 for part in parts:
56 if part == "length":
57 return len(current) if isinstance(current, list) else None
58 m = re.match(r"^(.+)\[(\d+)\]$", part)
59 if m:
60 name, idx = m.group(1), int(m.group(2))
61 arr = current.get(name) if isinstance(current, dict) else None
62 if not isinstance(arr, list) or idx >= len(arr):
63 return None
64 current = arr[idx]
65 else:
66 if not isinstance(current, dict):
67 return None
68 current = current.get(part)
69 return current
70
71
72def values_equal(json_val: Any, yaml_val: Any) -> bool:

Callers 1

_exec_requestMethod · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected