crv.core.serde
Experimental API
crv.core.serde
Lightweight JSON serialization/deserialization utilities.
Provides json_loads as a thin wrapper around the stdlib json module and
re-exports json_dumps_canonical from crv.core.hashing to ensure a single
canonical JSON policy across the codebase. This module is zero-IO.
Notes
- Use
json_dumps_canonicalfor deterministic JSON strings prior to hashing, caching, or persistence. - No side effects; stdlib-only.
References
- specs: src/crv/core/.specs/spec-0.1.md, spec-0.2.md
crv.core.serde.json_dumps_canonical
Serialize an object to a canonical JSON string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
typing.Any
|
JSON-serializable object. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Canonical JSON string with sort_keys=True, compact separators, |
str
|
and ensure_ascii=False. |
Notes
This function assumes the input is JSON-serializable and does not perform coercion of unsupported types.
Source code in src/crv/core/hashing.py
crv.core.serde.json_loads
Deserialize a JSON string to Python objects using the stdlib json module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s
|
str
|
JSON string to parse. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
typing.Any
|
Decoded Python object (dict, list, str, int, float, bool, or None). |
Notes
- No datetime parsing or custom hooks here; the core remains pure.
- For canonical serialization (for hashing), use
json_dumps_canonical.