初始化提交
This commit is contained in:
commit
887c1f449e
963 files changed
+166869
No files matched your search
@@ -0,0 +1,22 @@
|
||||
"""JSON 文本字段转换工具。"""
|
||||
|
||||
import json
|
||||
from typing import Any
|
||||
|
||||
|
||||
def dumps(value: Any) -> str:
|
||||
return json.dumps(value, ensure_ascii=False, separators=(",", ":"))
|
||||
|
||||
|
||||
def loads_dict(value: str | None) -> dict[str, Any]:
|
||||
if not value:
|
||||
return {}
|
||||
data = json.loads(value)
|
||||
return data if isinstance(data, dict) else {}
|
||||
|
||||
|
||||
def loads_list(value: str | None) -> list[str]:
|
||||
if not value:
|
||||
return []
|
||||
data = json.loads(value)
|
||||
return data if isinstance(data, list) else []
|
||||
Reference in new issue
Block a user