Pretty printing all JSON output in Silex PHP

If you’re doing some REST-ish API with Silex, or at least you need to output JSON. You’re probably doing something like this :

But, you surely want something well-presented like with the JSON_PRETTY_PRINT flag you pass to the json_encode function when you do it in flat PHP.

Don’t worry, here’s the tip using after middleware (if you don’t already know them) :

You just have to write this before running your app.