Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get the Pyramid json renderer to output formatted, pretty printed, output?

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?

like image 517
Thrill Science Avatar asked Aug 01 '13 22:08

Thrill Science


1 Answers

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')
like image 176
Thrill Science Avatar answered Sep 19 '22 12:09

Thrill Science