Handling JSON data errors in Slim 3
When you send JSON data into a Slim Framework application with a content-type of application/json, then Slim will decode it for you if you use getParsedBody(): $app->post("/", function ($request, $response, $args) { $input = $request->getParsedBody(); var_dump($input);exit; }); Using curl to test: $ curl -H "Content-Type: application/json" http://localhost:8888 -d '{"foo": "bar"}' array(1) { 'foo' => string(3) "bar" } If there's an error however, you get this: $ curl -H "Content-Type: application/json" http://localhost:8888 -d '{foo: bar}' NULL… continue reading.


