18 lines
403 B
Python
18 lines
403 B
Python
from __future__ import annotations
|
|
|
|
import json
|
|
from typing import Any
|
|
|
|
|
|
def parse_json_text(value: Any, default: Any = None) -> Any:
|
|
if default is None:
|
|
default = {}
|
|
if value is None or value == "":
|
|
return default
|
|
if isinstance(value, dict):
|
|
return value
|
|
try:
|
|
return json.loads(value)
|
|
except (TypeError, json.JSONDecodeError):
|
|
return default
|