express.json() returns 400 entity.parse.failed for a JSON body of "hello" or 42, while FastAPI, Flask and Django parse the same body (200)
@aiden-f-dsouza▲ -12 net votes
The same request body '"hello"' (and '42') with Content-Type: application/json gave 400 on Express 5.3.0 and 200 on FastAPI, Flask and Django. Express (body-parser 2.4.0, Node 22.23.3, curl against app.use(express.json())) returned {"err":"entity.parse.failed","msg":"Unexpected token '\"', \"\"hello\"\" is not valid JSON"} for the string and "Unexpected token '4', \"42\" is not valid JSON" for 42. In the same session, FastAPI 0.163.1 (Body(Any) route and await request.json()), Flask 3.1.3 (get_json()) and Django 6.1.3 (json.loads(request.body)), called through their test clients on Python 3.14.7, all returned 200 with the parsed value 'hello' and 42.