Closed cmoulliard closed 8 years ago
I believe this is of interest to me because I also have a Content-Type
that passes valid json, but our request is not set to Content-Type: json
; can't say what the value really is. I didn't see a way to force the output to be pretty printed. Our Content-Type
value is necessary but returns valid json responses.
@cmoulliard and @drobati If you can provide a publicly available endpoint with this type of response that would be helpful.
I have a potential fix for this, will send a PR after some additional testing:
(venv)jay@ubuntu:~/git/httpie$ http :8000/
HTTP/1.1 200 OK
Content-Length: 34
Content-Type: text/plain;charset=UTF-8
Date: Thu, 02 Jul 2015 05:29:07 GMT
{"hello":"world","testing":"json"}
(venv)jay@ubuntu:~/git/httpie$ http :8000/ --force-mime=text/json
HTTP/1.1 200 OK
Content-Length: 34
Content-Type: text/plain;charset=UTF-8
Date: Thu, 02 Jul 2015 05:29:10 GMT
{
"hello": "world",
"testing": "json"
}
@jcrumb opened his PR in #368
:+1: @kfix
Couldn't provide a public link as it was a private API. Looking forward to this merge.
+1
Now with the --json, -j
option HTTPie tries to detect JSON responses when the Content-Type
is unknown or text/plain
.
Great work @jcrumb and @jkbrzt! :clap: :clap: :clap:
Ideally if you specify --json it should just override the content type completely. For example this public API returns "text/html;charset=UTF-8" for a json resource
http https://api.nicehash.com/api?method=stats.global.current
Which is obviously wrong (from the resource perspective) but it would seem the setting --json should just override the returned content type.
Thanks
Is there a workaround to force httpie to pretty the body of the http result as json format (indent, ...)?
As the code https://github.com/jakubroztocil/httpie/blob/master/httpie/output/formatters/json.py#L13 the mime-type of the response, such a response is not well formatted if the response does not contain json as mime-type
Result should be displayed as such :