JSON Format
Lodum provides comprehensive JSON support with both in-memory and streaming capabilities.Installation
JSON support is built into Lodum core with no additional dependencies required:ijson dependency:
API Reference
dump()
obj: The object to encode (must be a@lodum-decorated class)target: Optional file-like object or Path to write to**kwargs: Additional arguments forjson.dump(s)(e.g.,indent)
- The JSON string if
targetis None, otherwise None
target is provided, O(1) streaming is used and some formatting kwargs might be ignored.
Example:
dumps()
dump(obj). Provided for compatibility.
load()
cls: The class to instantiatesource: JSON string, file-like object, or Pathmax_size: Maximum allowed size for string input (default: 10MB)
- An instance of
cls
loads()
load(cls, source). Provided for compatibility.
stream()
cls. Intended for sources containing a top-level array of objects.
Parameters:
cls: The class to instantiate for each itemsource: A binary stream, file-like object, or Path to a JSON array
- An iterator yielding instances of
cls
ijson library (install with pip install lodum[ijson])
Example:
load_stream()
stream(cls, source). Provided for compatibility.
schema()
Binary Data Handling
JSON doesn’t natively support binary data. Lodum automatically encodesbytes fields using base64: