Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
37a197e7f1 | ||
|
|
74cb3d2c54 | ||
|
|
d19abcabc7 |
@@ -1,7 +1,7 @@
|
|||||||
# MARK: Project info
|
# MARK: Project info
|
||||||
[project]
|
[project]
|
||||||
name = "corelibs"
|
name = "corelibs"
|
||||||
version = "0.22.5"
|
version = "0.23.0"
|
||||||
description = "Collection of utils for Python scripts"
|
description = "Collection of utils for Python scripts"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.13"
|
requires-python = ">=3.13"
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import json
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
def dump_data(data: Any) -> str:
|
def dump_data(data: Any, use_indent: bool = True) -> str:
|
||||||
"""
|
"""
|
||||||
dump formated output from dict/list
|
dump formated output from dict/list
|
||||||
|
|
||||||
@@ -16,6 +16,7 @@ def dump_data(data: Any) -> str:
|
|||||||
Returns:
|
Returns:
|
||||||
str: _description_
|
str: _description_
|
||||||
"""
|
"""
|
||||||
return json.dumps(data, indent=4, ensure_ascii=False, default=str)
|
indent = 4 if use_indent else None
|
||||||
|
return json.dumps(data, indent=indent, ensure_ascii=False, default=str)
|
||||||
|
|
||||||
# __END__
|
# __END__
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ json encoder for datetime
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from json import JSONEncoder
|
from json import JSONEncoder, dumps
|
||||||
from datetime import datetime, date
|
from datetime import datetime, date
|
||||||
|
|
||||||
|
|
||||||
@@ -28,4 +28,16 @@ def default(obj: Any) -> str | None:
|
|||||||
return obj.isoformat()
|
return obj.isoformat()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def json_dumps(data: Any):
|
||||||
|
"""
|
||||||
|
wrapper for json.dumps with sure dump without throwing Exceptions
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
data {Any} -- _description_
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
_type_ -- _description_
|
||||||
|
"""
|
||||||
|
return dumps(data, ensure_ascii=False, default=str)
|
||||||
|
|
||||||
# __END__
|
# __END__
|
||||||
|
|||||||
Reference in New Issue
Block a user