mirror of https://github.com/tiangolo/fastapi.git
43 lines
1.5 KiB
Markdown
43 lines
1.5 KiB
Markdown
# 🎻 🔗 🔢
|
||
|
||
📤 💼 🌐❔ 👆 5️⃣📆 💪 🗜 💽 🆎 (💖 Pydantic 🏷) 🕳 🔗 ⏮️ 🎻 (💖 `dict`, `list`, ♒️).
|
||
|
||
🖼, 🚥 👆 💪 🏪 ⚫️ 💽.
|
||
|
||
👈, **FastAPI** 🚚 `jsonable_encoder()` 🔢.
|
||
|
||
## ⚙️ `jsonable_encoder`
|
||
|
||
➡️ 🌈 👈 👆 ✔️ 💽 `fake_db` 👈 🕴 📨 🎻 🔗 💽.
|
||
|
||
🖼, ⚫️ 🚫 📨 `datetime` 🎚, 👈 🚫 🔗 ⏮️ 🎻.
|
||
|
||
, `datetime` 🎚 🔜 ✔️ 🗜 `str` ⚗ 💽 <a href="https://en.wikipedia.org/wiki/ISO_8601" class="external-link" target="_blank">💾 📁</a>.
|
||
|
||
🎏 🌌, 👉 💽 🚫🔜 📨 Pydantic 🏷 (🎚 ⏮️ 🔢), 🕴 `dict`.
|
||
|
||
👆 💪 ⚙️ `jsonable_encoder` 👈.
|
||
|
||
⚫️ 📨 🎚, 💖 Pydantic 🏷, & 📨 🎻 🔗 ⏬:
|
||
|
||
=== "🐍 3️⃣.6️⃣ & 🔛"
|
||
|
||
```Python hl_lines="5 22"
|
||
{!> ../../../docs_src/encoder/tutorial001.py!}
|
||
```
|
||
|
||
=== "🐍 3️⃣.1️⃣0️⃣ & 🔛"
|
||
|
||
```Python hl_lines="4 21"
|
||
{!> ../../../docs_src/encoder/tutorial001_py310.py!}
|
||
```
|
||
|
||
👉 🖼, ⚫️ 🔜 🗜 Pydantic 🏷 `dict`, & `datetime` `str`.
|
||
|
||
🏁 🤙 ⚫️ 🕳 👈 💪 🗜 ⏮️ 🐍 🐩 <a href="https://docs.python.org/3/library/json.html#json.dumps" class="external-link" target="_blank">`json.dumps()`</a>.
|
||
|
||
⚫️ 🚫 📨 ⭕ `str` ⚗ 💽 🎻 📁 (🎻). ⚫️ 📨 🐍 🐩 💽 📊 (✅ `dict`) ⏮️ 💲 & 🎧-💲 👈 🌐 🔗 ⏮️ 🎻.
|
||
|
||
!!! note
|
||
`jsonable_encoder` 🤙 ⚙️ **FastAPI** 🔘 🗜 💽. ✋️ ⚫️ ⚠ 📚 🎏 😐.
|