Orange-OpenSource / hurl

Hurl, run and test HTTP requests with plain text.
https://hurl.dev
Apache License 2.0
12.68k stars 476 forks source link

Pretty-Print / Format JSON Response Bodies #1760

Open Nezteb opened 1 year ago

Nezteb commented 1 year ago

Problem to solve

By default it seems that any JSON printed by hurl is not pretty-printed. Sometimes when I'm developing/debugging an API, I like to inspect the resulting JSON, which isn't doable in hurl without external tools.

This same feature request could also apply to HTML and XML, but at least for my use-case I am only asking for JSON. 😅

Proposal

Kind of similar to https://github.com/Orange-OpenSource/hurl/issues/1745, but I'd suggest either a CLI flag for this and/or a [Option] property to enable pretty printing for either an entire .hurl file or a single request.

Something like:

hurl test.hurl --pretty-print # or maybe something more descriptive and specific to JSON

and/or:

GET https://jsonplaceholder.typicode.com/users
[Option]
pretty-print: true # or maybe something more descriptive and specific to JSON

Additional context and resources

I currently pipe my hurl commands to jq to get the pretty-printed version of the JSON: https://github.com/jqlang/jq

However, this only works if I'm only printing a single response body; otherwise the printed output isn't valid JSON.

chrisguest75 commented 3 months ago

Or an option to dump the responses into folders under a subpath. It would also help when writing tests and creating assertions.

[Option]
responses-path: ./out/runs
write-responses: true 

Although using the curl output is very useful. :-)

jcamiel commented 3 months ago

Hi @chrisguest75, unless I've mistaken your point, you can do this with --output:

GET https://foo.com
[Options]
output: response.bin
HTTP 200
chrisguest75 commented 3 months ago

Thanks, that does work for me @jcamiel. I had to update to 4.3.0 first though. Didn't realise I was using an older version.