Files
QuantDinger/backend_api_python/app/utils/json_helpers.py
T
Dinger e27b7fbaca v4.0.4
Signed-off-by: Dinger <quantdinger@gmail.com>
2026-06-29 03:58:28 +08:00

21 lines
535 B
Python

"""Small JSON helper functions shared by services."""
from __future__ import annotations
import json
from typing import Any
def safe_json_loads(value: Any, default: Any = None) -> Any:
"""Parse JSON-like input without raising on malformed values."""
if default is None:
default = {}
if isinstance(value, (dict, list)):
return value
if isinstance(value, str) and value.strip():
try:
return json.loads(value)
except Exception:
return default
return default