-
Notifications
You must be signed in to change notification settings - Fork 498
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
API: Pretty print JSON responses #830
Comments
This sounds like a good idea - there pretty-print could also be used for Mercè Crosas, Ph.D. On Mon, Aug 18, 2014 at 8:56 AM, Philip Durbin [email protected]
|
Updating my last proposal - single filter, tests for pretty=true in requests, prettifies if response type is application/json. off by default, on in "dev mode". This way, we keep the url the same. |
I manually pretty-print the example JSON output at http://guides.dataverse.org/en/latest/api/search.html so that it's readable. |
I have a need to pretty print JSON while working on #2579 for debugging purposes (so I can actually read the JSON) so I created a method for this at 2e75546 because from what I could tell my previous code for pretty printing JSON was deleted as part of fa26ec8 . The methods are different and this time I wrote tests so I'm happier with the new method. If I'm duplicating effort, please let me know. |
My objection to doing this on the server side if not because of effort duplication. The problem is the unbounded contiguous memory allocation that this feature requires, and the fact that it's easy to do on the client side with jq or (my new favorite) HTTPie (https://github.com/jkbrzt/httpie https://github.com/jkbrzt/httpie). Client-side solution also gets you syntax coloring. As long as it's not public API, that's fine. If we need this on a public API, I'd go with a web filter, and put some effort into implementing this in a stream, not a string.
|
@michbarsinai my use case is pretty printing the JSON in the Glassfish logs: 9b04e1a#diff-a921aa2648ecc0764975a817168935fbR32 . It's for development, for now. I'm probably commenting on the wrong issue since this one is about what we expose via the API but we have enough issues and I didn't want to create a new one about pretty printing JSON for debugging purposes. Mostly I made the comment so someone like you or @ekraffmiller or whoever else can say, "hey, we already have a method for this and it's over here." :) |
You need to try HTTPie, man. Literally go:
and you get the colors for free :-)
|
@michbarsinai ok, I brew installed it. It doesn't help with my use case but it's a nice tool. Thanks. :) |
I think this would be a very nice and low-hanging-fruit feature but users aren't exactly clamoring for it so I vote we close it until there's actual user demand. |
No one seems to want this but me so I guess I'll close this issue. |
Many RESTful APIs such as GitHub's pretty-print the JSON response, indenting it so it's readable.
For efficiency,
javax.json
(Jersey) does not pretty print JSON. One workaround looks something like this...... but a better way suggested by @michbarsinai is to add a pretty-printing filter per http://docs.oracle.com/javaee/7/tutorial/doc/servlets006.htm
Perhaps by default the JSON would continue to be non-pretty for performance and efficiency but the the pretty-printing filter could be enabled with a config option.
The text was updated successfully, but these errors were encountered: