ring-clojure / ring-json

Ring middleware for handling JSON
313 stars 47 forks source link

pretty-printing support #45

Closed erjoalgo closed 8 years ago

erjoalgo commented 8 years ago

I may have missed it, but is there support for pretty-printing JSON responses?

I'm looking for something like python's json indent option:

python
Python 2.7.9 (default, Mar  1 2015, 12:57:24) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
>>> json.dump({"a" : 1, "b" : 2}, sys.stdout)
{"a": 1, "b": 2}>>> 
>>> json.dump({"a" : 1, "b" : 2}, sys.stdout, indent = 2)
{
  "a": 1, 
  "b": 2
}>>> 
erjoalgo commented 8 years ago

I manually used

(-> my-json-string (generate-string {:pretty true}))

Although I could've used

(-> my-handler (wrap-json-response {:pretty true}))

I found this by looking at the source, I think it would be good to add this to the doc/example since this looks like it should be a common request.