--- a/src/pyams_utils/json.py Wed Nov 20 19:26:23 2019 +0100
+++ b/src/pyams_utils/json.py Fri Nov 22 18:51:37 2019 +0100
@@ -10,26 +10,36 @@
# FOR A PARTICULAR PURPOSE.
#
-__docformat__ = 'restructuredtext'
+"""PyAMS_utils.json package
+
+A small utility module which provides a default JSON encoder to automatically convert
+dates and datetimes to ISO format
+ >>> import json as stock_json
+ >>> from datetime import datetime
+ >>> from pyams_utils import json
+ >>> from pyams_utils.timezone import GMT
-# import standard library
+ >>> value = datetime.fromtimestamp(1205000000, GMT)
+ >>> stock_json.dumps(value)
+ '"2008-03-08T18:13:20+00:00"'
+"""
+
import json
from datetime import date, datetime
-# import interfaces
-
-# import packages
+__docformat__ = 'restructuredtext'
def default_json_encoder(obj):
+ """Default JSON encoding of dates and datetimes"""
if isinstance(obj, (date, datetime)):
return obj.isoformat()
- else:
- return obj
+ return obj
+# pylint: disable=protected-access
json._default_encoder = json.JSONEncoder(skipkeys=False,
ensure_ascii=True,
check_circular=True,