-
-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathdump.py
More file actions
18 lines (15 loc) · 514 Bytes
/
dump.py
File metadata and controls
18 lines (15 loc) · 514 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from typing import Any
from benedict.serializers import JSONSerializer
def dump(obj: Any, **kwargs: Any) -> str:
serializer = JSONSerializer()
options = {"indent": 4, "sort_keys": True}
options.update(**kwargs)
try:
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