parseur.utils¶
Attributes¶
Classes¶
JSON Encoder that converts datetime and date objects to ISO 8601 strings. |
Functions¶
|
Serialize a Python object to a JSON-formatted string with ISO datetime support. |
Module Contents¶
- class parseur.utils.ISODateJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]¶
Bases:
json.JSONEncoderJSON Encoder that converts datetime and date objects to ISO 8601 strings.
- default(obj)[source]¶
Implement this method in a subclass such that it returns a serializable object for
o, or calls the base implementation (to raise aTypeError).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
- parseur.utils.to_json(data, indent=2, sort_keys=True, ensure_ascii=False)[source]¶
Serialize a Python object to a JSON-formatted string with ISO datetime support.
This function uses the custom ISODateJSONEncoder to automatically convert datetime.datetime objects to ISO 8601 strings.
- Parameters:
data – The data to serialize (dict, list, etc.).
indent – Number of spaces to indent in the output JSON. Default is 2.
sort_keys – Whether to sort the dictionary keys in the output. Default is True.
ensure_ascii – Whether to escape non-ASCII characters. Default is False.
- Returns:
A JSON-formatted string.