Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 10 of 51 for jsonable_encoder (0.3 sec)

  1. tests/test_jsonable_encoder.py

        pet = {"name": "Firulais", "owner": {"name": "Foo"}}
        assert jsonable_encoder(pet) == {"name": "Firulais", "owner": {"name": "Foo"}}
        assert jsonable_encoder(pet, include={"name"}) == {"name": "Firulais"}
        assert jsonable_encoder(pet, exclude={"owner"}) == {"name": "Firulais"}
        assert jsonable_encoder(pet, include={}) == {}
        assert jsonable_encoder(pet, exclude={}) == {
            "name": "Firulais",
    Python
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Thu Apr 18 21:56:59 GMT 2024
    - 9K bytes
    - Viewed (0)
  2. docs/en/docs/tutorial/encoder.md

    For example, if you need to store it in a database.
    
    For that, **FastAPI** provides a `jsonable_encoder()` function.
    
    ## Using the `jsonable_encoder`
    
    Let's imagine that you have a database `fake_db` that only receives JSON compatible data.
    
    For example, it doesn't receive `datetime` objects, as those are not compatible with JSON.
    
    Plain Text
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Tue Oct 17 05:59:11 GMT 2023
    - 1.8K bytes
    - Viewed (0)
  3. docs/zh/docs/tutorial/encoder.md

    比如,如果您需要将其存储在数据库中。
    
    对于这种要求, **FastAPI**提供了`jsonable_encoder()`函数。
    
    ## 使用`jsonable_encoder`
    
    让我们假设你有一个数据库名为`fake_db`,它只能接收与JSON兼容的数据。
    
    例如,它不接收`datetime`这类的对象,因为这些对象与JSON不兼容。
    
    因此,`datetime`对象必须将转换为包含<a href="https://en.wikipedia.org/wiki/ISO_8601" class="external-link" target="_blank">ISO格式化</a>的`str`类型对象。
    
    同样,这个数据库也不会接收Pydantic模型(带有属性的对象),而只接收`dict`。
    
    对此你可以使用`jsonable_encoder`。
    
    它接收一个对象,比如Pydantic模型,并会返回一个JSON兼容的版本:
    
    Plain Text
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Tue Oct 17 05:59:11 GMT 2023
    - 1.7K bytes
    - Viewed (0)
  4. docs/ja/docs/tutorial/encoder.md

    # JSON互換エンコーダ
    
    データ型(Pydanticモデルのような)をJSONと互換性のあるもの(`dict`や`list`など)に変更する必要がある場合があります。
    
    例えば、データベースに保存する必要がある場合です。
    
    そのために、**FastAPI** は`jsonable_encoder()`関数を提供しています。
    
    ## `jsonable_encoder`の使用
    
    JSON互換のデータのみを受信するデータベース`fase_db`があるとしましょう。
    
    例えば、`datetime`オブジェクトはJSONと互換性がないので、このデーターベースには受け取られません。
    
    そのため、`datetime`オブジェクトは<a href="https://en.wikipedia.org/wiki/ISO_8601" class="external-link" target="_blank">ISO形式</a>のデータを含む`str`に変換されなければなりません。
    
    Plain Text
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Mon Jan 22 20:09:02 GMT 2024
    - 1.9K bytes
    - Viewed (0)
  5. docs_src/encoder/tutorial001.py

    from fastapi import FastAPI
    from fastapi.encoders import jsonable_encoder
    from pydantic import BaseModel
    
    fake_db = {}
    
    
    class Item(BaseModel):
        title: str
        timestamp: datetime
        description: Union[str, None] = None
    
    
    app = FastAPI()
    
    
    @app.put("/items/{id}")
    def update_item(id: str, item: Item):
        json_compatible_item_data = jsonable_encoder(item)
    Python
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Sat May 14 11:59:59 GMT 2022
    - 461 bytes
    - Viewed (0)
  6. docs/pt/docs/tutorial/encoder.md

    Por exemplo, se você precisar armazená-lo em um banco de dados.
    
    Para isso, **FastAPI** fornece uma função `jsonable_encoder()`.
    
    ## Usando a função `jsonable_encoder`
    
    Vamos imaginar que você tenha um banco de dados `fake_db` que recebe apenas dados compatíveis com JSON.
    
    Plain Text
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Thu Apr 18 19:53:19 GMT 2024
    - 1.9K bytes
    - Viewed (0)
  7. docs/ru/docs/tutorial/encoder.md

    Например, если необходимо хранить его в базе данных.
    
    Для этого **FastAPI** предоставляет функцию `jsonable_encoder()`.
    
    ## Использование `jsonable_encoder`
    
    Представим, что у вас есть база данных `fake_db`, которая принимает только JSON-совместимые данные.
    
    Например, он не принимает объекты `datetime`, так как они не совместимы с JSON.
    
    Plain Text
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Tue Jan 23 13:56:12 GMT 2024
    - 2.8K bytes
    - Viewed (0)
  8. docs/em/docs/tutorial/encoder.md

    # 🎻 🔗 🔢
    
    📤 💼 🌐❔ 👆 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>.
    
    Plain Text
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Sat Apr 01 09:26:04 GMT 2023
    - 1.5K bytes
    - Viewed (0)
  9. docs/uk/docs/tutorial/encoder.md

    Наприклад, якщо вам потрібно зберегти це в базі даних.
    
    Для цього, **FastAPI** надає `jsonable_encoder()` функцію.
    
    ## Використання `jsonable_encoder`
    
    Давайте уявимо, що у вас є база даних `fake_db`, яка приймає лише дані, сумісні з JSON.
    
    Наприклад, вона не приймає об'єкти типу `datetime`, оскільки вони не сумісні з JSON.
    
    Plain Text
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Thu Apr 18 19:53:19 GMT 2024
    - 2.6K bytes
    - Viewed (0)
  10. fastapi/encoders.py

                ):
                    encoded_key = jsonable_encoder(
                        key,
                        by_alias=by_alias,
                        exclude_unset=exclude_unset,
                        exclude_none=exclude_none,
                        custom_encoder=custom_encoder,
                        sqlalchemy_safe=sqlalchemy_safe,
                    )
                    encoded_value = jsonable_encoder(
                        value,
    Python
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Thu Apr 18 21:56:59 GMT 2024
    - 10.8K bytes
    - Viewed (0)
Back to top