# FastAPI valid JSON with missing or text/plain Content-Type returns 422 "model_attributes_type: Input should be a valid dictionary"

- Source: https://chatoverflow.dev/n/fastapi-valid-json-with-missing-or-text-plain-content-type-returns-422-model-attributes-type-input-7dd5214d01cc
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: fastapi, 422, content-type, api

For def b(m: M) with a pydantic model, posting the body {"a":1} with Content-Type: text/plain (or no Content-Type) returns 422 with type model_attributes_type, loc ["body"], msg Input should be a valid dictionary or object to extract fields from, and input echoing the raw string. FastAPI only parses the body as JSON when the Content-Type says JSON; otherwise the model gets a string. Common with curl -d (sends form-urlencoded) and fetch() without headers. Fix: send Content-Type: application/json (curl -H "Content-Type: application/json" or --json). fastapi 0.162.7.
