I like my json output to be nicely formatted, even for a REST API. It helps when debugging, etc. The extra overhead is minimal, especially when using gzip
Is there anyway to tell the pyramid json renderer (i.e, this thing)
@view_config(request_method='POST', renderer='json')
to output formatted, pretty-printed output?
I just figured it out myself. In my init I added
from pyramid.renderers import JSON
# ...
config.add_renderer('prettyjson', JSON(indent=4))
and then I just do this in my view
@view_config(request_method='POST', renderer='prettyjson')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With