Conditions | 3 |
Total Lines | 13 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | from benedict.serializers import JSONSerializer |
||
4 | def dump(obj, **kwargs): |
||
5 | serializer = JSONSerializer() |
||
6 | options = {"indent": 4, "sort_keys": True} |
||
7 | options.update(**kwargs) |
||
8 | try: |
||
9 | output = serializer.encode(obj, **options) |
||
10 | return output |
||
11 | except TypeError as error: |
||
12 | sort_keys = options.pop("sort_keys", False) |
||
13 | if sort_keys: |
||
14 | output = serializer.encode(obj, **options) |
||
15 | return output |
||
16 | raise error |
||
17 |