Search Options

Display Count
Sort
Preferred Language
Advanced Search

Results 1 - 10 of 93 for jsonable_encoder (0.18 seconds)

  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",
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Tue Feb 17 09:59:14 GMT 2026
    - 9.2K bytes
    - Click Count (0)
  2. docs/ko/docs/tutorial/encoder.md

    # JSON 호환 가능 인코더 { #json-compatible-encoder }
    
    데이터 유형(예: Pydantic 모델)을 JSON과 호환되는 형태(예: `dict`, `list` 등)로 변환해야 하는 경우가 있습니다.
    
    예를 들면, 데이터베이스에 저장해야 하는 경우입니다.
    
    이를 위해, **FastAPI**에서는 `jsonable_encoder()` 함수를 제공합니다.
    
    ## `jsonable_encoder` 사용 { #using-the-jsonable-encoder }
    
    JSON 호환 가능 데이터만 수신하는 `fake_db` 데이터베이스가 존재한다고 가정하겠습니다.
    
    예를 들면, `datetime` 객체는 JSON과 호환되지 않으므로 이 데이터베이스는 이를 받지 않습니다.
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 14:06:26 GMT 2026
    - 1.8K bytes
    - Click Count (0)
  3. docs/ja/docs/tutorial/encoder.md

    # JSON互換エンコーダ { #json-compatible-encoder }
    
    データ型(Pydanticモデルのような)をJSONと互換性のあるもの(`dict`や`list`など)に変換する必要があるケースがあります。
    
    例えば、データベースに保存する必要がある場合です。
    
    そのために、**FastAPI** は`jsonable_encoder()`関数を提供しています。
    
    ## `jsonable_encoder`の使用 { #using-the-jsonable-encoder }
    
    JSON互換のデータのみを受信するデータベース`fake_db`があるとしましょう。
    
    例えば、`datetime`オブジェクトはJSONと互換性がないので、受け取られません。
    
    そのため、`datetime`オブジェクトは[ISO形式](https://en.wikipedia.org/wiki/ISO_8601)のデータを含む`str`に変換されなければなりません。
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 14:07:17 GMT 2026
    - 1.8K bytes
    - Click Count (0)
  4. 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` { #using-the-jsonable-encoder }
    
    Let's imagine that you have a database `fake_db` that only receives JSON compatible data.
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Mar 05 18:13:19 GMT 2026
    - 1.6K bytes
    - Click Count (0)
  5. docs/zh-hant/docs/tutorial/encoder.md

    例如,當你需要把它儲存在資料庫中。
    
    為此,**FastAPI** 提供了 `jsonable_encoder()` 函式。
    
    ## 使用 `jsonable_encoder` { #using-the-jsonable-encoder }
    
    想像你有一個只接受與 JSON 相容資料的資料庫 `fake_db`。
    
    例如,它不接受 `datetime` 物件,因為那與 JSON 不相容。
    
    因此,必須將 `datetime` 物件轉為一個以 [ISO 格式](https://en.wikipedia.org/wiki/ISO_8601) 表示資料的 `str`。
    
    同樣地,這個資料庫不會接受 Pydantic 模型(帶有屬性的物件),只接受 `dict`。
    
    你可以使用 `jsonable_encoder` 來處理。
    
    它接收一個物件(例如 Pydantic 模型),並回傳一個與 JSON 相容的版本:
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 17:05:38 GMT 2026
    - 1.5K bytes
    - Click Count (0)
  6. docs/zh/docs/tutorial/encoder.md

    比如,如果您需要将其存储在数据库中。
    
    对于这种要求, **FastAPI**提供了`jsonable_encoder()`函数。
    
    ## 使用`jsonable_encoder` { #using-the-jsonable-encoder }
    
    让我们假设你有一个数据库名为`fake_db`,它只能接收与JSON兼容的数据。
    
    例如,它不接收`datetime`这类的对象,因为这些对象与JSON不兼容。
    
    因此,`datetime`对象必须转换为包含[ISO 格式](https://en.wikipedia.org/wiki/ISO_8601)的`str`类型对象。
    
    同样,这个数据库也不会接收Pydantic模型(带有属性的对象),而只接收`dict`。
    
    对此你可以使用`jsonable_encoder`。
    
    它接收一个对象,比如Pydantic模型,并会返回一个JSON兼容的版本:
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 17:06:37 GMT 2026
    - 1.5K bytes
    - Click Count (0)
  7. docs_src/body_updates/tutorial002_py310.py

    from fastapi import FastAPI
    from fastapi.encoders import jsonable_encoder
    from pydantic import BaseModel
    
    app = FastAPI()
    
    
    class Item(BaseModel):
        name: str | None = None
        description: str | None = None
        price: float | None = None
        tax: float = 10.5
        tags: list[str] = []
    
    
    items = {
        "foo": {"name": "Foo", "price": 50.2},
        "bar": {"name": "Bar", "description": "The bartenders", "price": 62, "tax": 20.2},
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Wed Feb 04 12:07:26 GMT 2026
    - 1009 bytes
    - Click Count (0)
  8. fastapi/encoders.py

            )
            return jsonable_encoder(
                obj_dict,
                exclude_none=exclude_none,
                exclude_defaults=exclude_defaults,
                sqlalchemy_safe=sqlalchemy_safe,
            )
        if dataclasses.is_dataclass(obj):
            assert not isinstance(obj, type)
            obj_dict = dataclasses.asdict(obj)
            return jsonable_encoder(
                obj_dict,
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Sun Mar 15 11:44:39 GMT 2026
    - 10.9K bytes
    - Click Count (0)
  9. docs/en/docs/advanced/response-directly.md

    If you declare a [Response Model](../tutorial/response-model.md) FastAPI will use it to serialize the data to JSON, using Pydantic.
    
    If you don't declare a response model, FastAPI will use the `jsonable_encoder` explained in [JSON Compatible Encoder](../tutorial/encoder.md) and put it in a `JSONResponse`.
    
    You could also create a `JSONResponse` directly and return it.
    
    /// tip
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Mar 05 18:13:19 GMT 2026
    - 4K bytes
    - Click Count (0)
  10. docs/ko/docs/tutorial/body-updates.md

    # Body - 업데이트 { #body-updates }
    
    ## `PUT`으로 교체 업데이트하기 { #update-replacing-with-put }
    
    항목을 업데이트하려면 [HTTP `PUT`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT) 작업을 사용할 수 있습니다.
    
    `jsonable_encoder`를 사용해 입력 데이터를 JSON으로 저장할 수 있는 데이터로 변환할 수 있습니다(예: NoSQL 데이터베이스 사용 시). 예를 들어 `datetime`을 `str`로 변환하는 경우입니다.
    
    {* ../../docs_src/body_updates/tutorial001_py310.py hl[28:33] *}
    
    `PUT`은 기존 데이터를 **대체**해야 하는 데이터를 받는 데 사용합니다.
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 14:06:26 GMT 2026
    - 4.8K bytes
    - Click Count (0)
Back to Top