Reference/Python
Python: JSON, types, and dicts
json.loads/dumps, dict key sets, and the action object {tool, args} used everywhere on Joeven.
JSON is the wire format of agents. Python's json module is stdlib.
Loads and dumps
| Call | Use |
|---|---|
json.loads(s) | string → object |
json.dumps(obj) | object → string |
json.dumps(obj, sort_keys=True, separators=(",", ":")) | canonical string for hashes |
json.dumps(obj, indent=2) | debug only (not for digests) |
Allowed JSON types: dict, list, str, int, float, bool, None. Not allowed: set, tuple (becomes list), custom classes.
python
import json
json.loads(class="tok-s">'{"tool":"geocode","args":{"city":"Paris"}}')
json.dumps({class="tok-s">"b": 1, class="tok-s">"a": 2}, sort_keys=True)Action object
Require exact keys:
set(obj.keys()) == {"tool", "args"}
| Check | Fail closed |
|---|---|
| not a dict | parse error |
| extra keys | parse error (injection hideout) |
tool not str | parse error |
args not dict | parse error |
Dict patterns
| Pattern | Meaning |
|---|---|
d.get(k) | missing → None |
d.get(k, default) | missing → default |
k in d | membership |
dict(d) | shallow copy |
{**d, k: v} | copy with override |
Tip:NeverevalJSON. Neverjson.loadson a value you already parsed into a dict.
Errors
json.JSONDecodeError is a ValueError. Catch both in parse retries. Do not catch Exception around tool bodies or you will hide bugs.