-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Option to allow pretty print without alpha sorting #128
Comments
Results from my introspection.
Since
Same result. Now looking into
Look into requests code
Trying other library like
Since the the returned object is dictionary it isn't possible to maintain the order due to hashing. If it is possible to maintain the order it would be great. |
Seems like I made a mistake. There is a JSONProcessor but still it might not solve the problem.
Trying with
|
One way to get around the problem is use
|
Nice. I recently used something called an OrderedHash is ruby that solved a similar problem. Thinking that OrderedDict might be the solution in python... |
@patcon That was easier solution than mine. I will modify the code accordingly and update the pull request. |
👍 Closing this one :) |
@patcon Why?, pull request isn't merged though. |
Ah. Oops. Misunderstood the context of the referring issue above. |
👍 veeery useful option, please merge/fix at the next convenient opportunity. If not "reasonably" soon, any idea of by when approximately? |
+1 |
+1 |
Any news about this? |
+1 |
1 similar comment
+1 |
This problem is indeed misleading. I struggled a bit to understand why my (server side) OrderedDict was not correctly serialised in my app, then I finally understood that the culprit was not the server but indeed the client re-sorting the keys. It is sometimes useful to have the keys sorted, but for an HTTP client, having a default that changes the response content does not sound like the right thing. Thanks for the amazing tool anyway ;) |
@jkbrzt: You mention a while back in #151 (comment) that you wanted a more generic solution to this problem; was any progress made on that? |
@msabramo it's still on my to do list but not progress yet |
+1 this really needs to become a feature. Thanks for this amazing tool! |
I wrote an HTTP client for Sublime Text that's also built on top of Requests, called Requester. I also wanted to allow users to choose whether or not keys for JSON responses are sorted, so I added a 'fmt' argument to calls to requests. I solved it like this. If the response body is JSON, calling |
Has this feature been added? I tried with
Anyway, just passing $ http --version
0.9.9 |
This feature should be default. I love HTTPie, but resorting the keys - while convenient for some usage - is confusing if you don't realize, that client tool does this. Piping |
Knock-knock... 7 years after... any updates? |
Anybody know of an httpie fork that took care of this annoying issue? |
I found the following workaround, instead of using httpie I found curlie, which seems to
So I can use it like this: $ curlie GET localhost:3000/tasks | jq -C
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Content-Length: 304
ETag: W/"130-ED1W4hQo1i7na7wy5Ewc7iKdoJc"
Date: Wed, 27 May 2020 06:28:26 GMT
Connection: keep-alive
[
{
"id": 2,
"title": "new task2",
"description": "description2",
"status": "OPEN"
},
{
"id": 3,
"title": "new task3",
"description": "description3",
"status": "OPEN"
}
] Where as with httpie I would the headers BTW, I created this convenient script: $ cat ~/bin/c
curlie "$@" | jq -C |
How about this? Disable the default header and JSON key sorting, and specify a custom JSON indent size: $ http --format-options headers.sort=false,json.sort_keys=false,json.indent=2 httpbin.org/get
It’s already |
The idea behind the syntax is to allow more options to be easily added in the future. But I do realise that it’s quite a verbose one. On the other hand, I would expect people to set it once in the config file and not type it manually. Thoughts? |
Thanks a lot for the reply, being able to configure those options for format output would be great, speacially if you can just put it on a conf file. I tried to install from master but I have the following issue:
Do I need python 3? |
@opensas thanks for testing it out! Yes, you need Python 3.6+ (Python 2.7 is dead, and since v2.0.0 HTTPie does not support it). |
@opensas if you have Docker installed, you can test it in a container: docker run --rm -it python:3.8-slim Then inside the container: pip install --upgrade https://github.com/jakubroztocil/httpie/archive/master.tar.gz $ http --version
2.2.0-dev |
I could install it with I tested it and it works ok with I'm trying to set those options in my config file, but I guess I have a trouble with the xx=xx options, I'm trying like this:
What should be the correct syntax for my config.json file? DO I have to escape the |
@opensas what output do you get when you run |
@opensas the syntax is correct (it should be the same like on the CLI, there nothing special about the config options). |
Sorry, I found the issue, I had a just removed the .httpie folder and now everything works as expected thanks a lot! I hope you can release this changes in the near future! Some feedback:
anyway, congrats on the excellent job you are doing |
more feedback: I think the easiest thing to use from the command line would be to allow something like:
|
The
Yes, it should be out pretty soon.
I agree that silently changing the output order is generally not a good idea. Here, however, it’s part of the "prettification" meant for human consumption on the terminal, and the HTTP header and JSON key order is insignificant. Also, this behaviour has been the default for a long time, so a lot of people would have to change their config files to get back what they’re used to.
Good point, a shortcut for toggling both the sortings might be handy. Thanks for the feedback! |
It acts as a shortcut for --format-options=json.sort_keys:false,headers.sort:false #128
Just released v2.2.0 that addresses this issue. Learn about about the new |
Right now, the options are
colors
,format
, andall
, but often the order of the json returned is intentional and for clarify. It would be nice to be able to pretty print the json without having it's keys sorted :)Awesome tool, and thanks very much for everything!
The text was updated successfully, but these errors were encountered: