2020-02-03 17:25:54 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2020-02-19 14:18:29 +00:00
|
|
|
from benedict.serializers import JSONSerializer
|
2020-02-06 14:18:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
def dump(obj, **kwargs):
|
2020-02-20 16:14:48 +00:00
|
|
|
serializer = JSONSerializer()
|
2020-02-06 14:18:01 +00:00
|
|
|
options = {
|
|
|
|
'indent': 4,
|
|
|
|
'sort_keys': True,
|
|
|
|
}
|
|
|
|
options.update(**kwargs)
|
|
|
|
try:
|
2020-02-19 14:18:29 +00:00
|
|
|
output = serializer.encode(obj, **options)
|
|
|
|
return output
|
|
|
|
except TypeError as error:
|
|
|
|
sort_keys = options.pop('sort_keys', False)
|
|
|
|
if sort_keys:
|
|
|
|
output = serializer.encode(obj, **options)
|
|
|
|
return output
|
|
|
|
raise error
|