Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

492
Views
FastAPI finds my JSON array of objects an invalid list

I'm using FastAPI and I'm trying to send a JSON array of JSON objects to my post endpoint, in the body. My endpoint is defined as:

@router.post("/create_mails")
def create_mails(notas: List[schemas.Nota], db: Session = Depends(get_db)):

My body in Postman looks like:

{
    "notas": [{"a":"1","b":"2","c":"3","d":"4"},
              {"a":"1","b":"2","c":"3","d":"4"}]
}

However, I keep getting the 422 unprocessable entity error from FastAPI, with the error detail:
value is not a valid list

I also tested it with a modified endpoint:

@router.post("/create_mails")
def create_mails(notas: List[str] = Body([]), db: Session = Depends(get_db)):

and with a simple string array, but the same error is returned.

Am I missing FastAPI's definition of a valid list?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I'm pretty sure your POST method parameter needs to model the entire request body, which is indeed a single object, and not a list.
To match the body you're trying to send, you'd need something like:

class NotaList(BaseModel):
    notas: List[Nota]

and then:

def create_mails(notas: schemas.NotaList) 
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!