mt940.json module¶
JSON serialization for MT940 models.
This module exposes JSONEncoder, a json.JSONEncoder subclass
that knows how to serialize the model types returned by the parser (balances,
amounts, dates and the transaction collections).
Example
>>> import json
>>> import mt940
>>> transactions = mt940.models.Transactions()
>>> json.dumps(transactions, cls=mt940.JSONEncoder)
'{"transactions": []}'
- class mt940.json.JSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]¶
Bases:
JSONEncoderSerialize MT940 model objects to JSON-compatible primitives.
Dates, datetimes, timedeltas, timezones and decimals are rendered as strings;
Transactions,Transaction,BalanceandAmountare rendered as theirdata/__dict__mappings. Pass it as theclsargument tojson.dumps().- default(o)[source]¶
Return a JSON-serializable representation of
o.- Parameters:
o (Any) – The object to serialize.
okeeps the permissiveAnytype of the overriddenjson.JSONEncoder.default().- Returns:
The serialized form of the object.
- Return type: