Fastapi: [QUESTION] List of JSON as Input without using BaseModel

Created on 6 Feb 2020  路  3Comments  路  Source: tiangolo/fastapi

First check

  • [x] I used the GitHub search to find a similar issue and didn't find it.
  • [x] I searched the FastAPI documentation, with the integrated search.
  • [x] I already searched in Google "How to X in FastAPI" and didn't find any information.

Description

How can I have a generic JSON as an input

"params": {
    "varA": {
      "x": "2",
      "version": 4
    },
    "y":  [{
              "p": 228.0,
              "q": "abcd"
            }]
}

If I define y: List[Json] I get:

"msg": "JSON object must be str, bytes or bytearray",
HTTP/1.1" 422 Unprocessable Entity

or y: List[str] or y: str
HTTP/1.1" 400 Bad Request

Is it possible to have a generic JSON List as an input instead of having to define a hard-coded Pydantic BaseModel?

question

Most helpful comment

y: List[dict] or y: List[typing.Any]?

All 3 comments

y: List[dict] or y: List[typing.Any]?

@phy25 - Thanks

Thanks for the help here @phy25 ! :cake: :bowing_man:

And thanks @alivcor for reporting back and closing the issue :+1:

Was this page helpful?
0 / 5 - 0 ratings