对不起,Python不是很精通.

I haven't found the docs for that use case. How can I get the request body, ensure its a valid Json (any valid json, including numbers, string, booleans and nulls, not only objects and arrays) and get the actual Json. Using pydantic forces the Json to have a specific structure.

推荐答案

You can find nearly everything inside the Request object

您可以使用request.json()获得请求正文,这将为您提供解析后的JSON作为字典.

from fastapi import Request, FastAPI

@app.post("/dummypath")
async def get_body(request: Request):
    return await request.json()

If you want access the body as string, you can use request.body()

Json相关问答推荐

输入请求中不存在null的条件抖动

PowerShell脚本-替换json数组(转义$var将被视为不带双引号的文本)

kotlinx-serialization:如何将具有不同类型对象的JsonArray转换为同一个Class

Flutter -控制器问题-JSON API

如何在Android中解析带有动态键和可变对象名称的改装JSON响应?

如何使用jq使用子值对象的键对json对象进行分组

当列为空时从 SQL 获取 JSON

JOLT 转换仅过滤一个字段

在Flutter 中将 map 的 Json 转换为 list

ORA-01422: 精确提取返回的行数超过了与 json 对象组合的请求数

从 PowerShell 编辑 Windows 终端配置文件设置 JSON

使用 BASH 和 JQ 我想将 json 文件与 bash 数组进行比较

无法向 Json 数组添加新元素

通过 RestAssured 中的 JsonPath 访问匿名数组的元素

使用 Node.js 对 JSON 中的字符串大小有限制吗?

如何使用 Gson 解码具有未知字段的 JSON?

在 JSON.NET 中序列化派生类时的字段顺序

确保数组中的项目属性在 Json Schema 中是唯一的?

从 JSON 到 JSONL 的 Python 转换

如何遍历 JSON 中的条目?