Translates a mapping / sequence recursively in the same fashion as `pydantic` v2's `model_dump(mode="json")`.
(data: object)
| 422 | |
| 423 | |
| 424 | def json_safe(data: object) -> object: |
| 425 | """Translates a mapping / sequence recursively in the same fashion |
| 426 | as `pydantic` v2's `model_dump(mode="json")`. |
| 427 | """ |
| 428 | if is_mapping(data): |
| 429 | return {json_safe(key): json_safe(value) for key, value in data.items()} |
| 430 | |
| 431 | if is_iterable(data) and not isinstance(data, (str, bytes, bytearray)): |
| 432 | return [json_safe(item) for item in data] |
| 433 | |
| 434 | if isinstance(data, (datetime, date)): |
| 435 | return data.isoformat() |
| 436 | |
| 437 | return data |
| 438 | |
| 439 | |
| 440 | def is_azure_client(client: object) -> TypeGuard[AzureOpenAI]: |
no test coverage detected