Skip to content
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

Pretty-Print / Format JSON Response Bodies #1760

Open
Nezteb opened this issue Jul 13, 2023 · 4 comments
Open

Pretty-Print / Format JSON Response Bodies #1760

Nezteb opened this issue Jul 13, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@Nezteb
Copy link

Nezteb commented Jul 13, 2023

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 #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
Copy link

chrisguest75 commented May 25, 2024

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
Copy link
Collaborator

jcamiel commented May 25, 2024

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
Copy link

chrisguest75 commented May 25, 2024

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.

@jcamiel jcamiel self-assigned this Jun 12, 2024
@oatnog
Copy link

oatnog commented Feb 2, 2025

Although it would be neat to have prettier JSON handling built in, I've been achieving something similar by piping output to jq.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants