-
-
Notifications
You must be signed in to change notification settings - Fork 769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make JSON printing a bit nicer #193
Conversation
@@ -46,7 +46,7 @@ def problem(status, title, detail, type='about:blank', instance=None, headers=No | |||
if ext: | |||
problem_response.update(ext) | |||
|
|||
body = json.dumps(problem_response) | |||
body = json.dumps(problem_response, indent=2) + "\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The + "\n"
means you create 3 string every time instead of 1.
The unit tests are also failing. |
Whoops, sorry yes I'd meant to ask about whether the implementation and functionality was ok before fixing up the tests. (On the one hand, copies always sound bad. On the other hand, there was just a I just switched the implementation to not do the copy (but instead pass a list to the Response — I'm less familiar with the Python WSGI ecosystem than the Ruby Rack one, but I believe this should be supported regardless of |
Is it really the frameworks responsibility to pretty print it? I mean, everyone working with REST has tools to pretty print it on their end. At the very least they can pipe it to python -m json.tool or jq. |
At Stripe, one of our core observations was that the little details are what changes an API from acceptable to actually a pleasure to use. (And particularly, the most important details happen during interactive development: when you're first Certainly developers can pipe the output of a curl to Regardless of the philosophy, this framework already does |
@gdb maybe you can consider using HTTPie, https://github.com/jkbrzt/httpie
I use it everyday to do REST calls 😄 |
HTTPie is great. Unfortunately, it's less about me developing my own API, and more about the external developers who are going to integrate against my API. |
@jmcs @rafaelcaricio what is now the status here (apart from merge conflicts)? I think the trailing newline is OK (we already have indent as @gdb points out). |
@hjacobs I guess it is fine to add the new-line. In the future we could add configuration to Connexion to enable "human readable JSON responses", so it would enable the indentation + newline. |
@gdb can you resolve the merge conflict to get this PR into master? Thanks! |
Ok! |
This change makes JSON generation more consistent and human-friendly:
curl
from the command line, without making the machine case worse.indent=2
to errors so they are pretty printed as well.