Yaak Logo
Yaak
Feedback/Response type override

Response type override

Jamie Carl·2 years ago
ReleasedFeature Request

I’m currently dealing with a poorly implemented RESTful API that returns a JSON response, but the Content-Type header is always text/html. This means that selecting the Pretty formatting in the response panel will try and make it pretty HTML, not JSON.

It would be SOOOOO incredibly fantastic if I could override the response type so that I can have the nice JSON formatting I get when the API is correctly implemented and returns application/json.

A simple solution may perhaps be in the response panel, you could add JSON next to Pretty and RAW to manually display the response as pretty JSON?

Linux2024.13.0

Comments (21)

Sign in to leave a comment.

Gregory Schier

I could have sworn I added logic to do this automatically, but it might only be for text plain. I’ll get that working

Jamie CarlOP

Thanks! You forget how useful collapsible JSON is until you don’t have it! LOL

Daniel Lewis

Also include for type “text/javascript”?

Gregory Schier

I forgot to put this in the changelog, but I believe it should be fixed now

Jamie CarlOP

What version is this released in? I have 2025.1.2 but it is still not working as expected. If that is the correct version, let me know if I need to supply logs or any further information. Thanks!

Gregory Schier

I used the following request to reproduce Yaak correctly highlighting the data:

```

curl -X POST 'https://yaak.app/x/echo'
--header 'Content-Type: text/html'
--data-raw '{ "foo": "bar" }'

```

The detection algorithm is fairly basic, so perhaps your returned JSON is not being detected? Yaak simply checks if the content starts with { or [ . Does your response start with whitespace or some other character that may be skipping this detection?

Jamie CarlOP

haha. Nailed it! I didn’t notice, but there is a single white-space character in front of the JSON.

Gregory Schier

Cool, I’ll make sure to handle that case!

Jamie CarlOP

Thanks, Greg. You’re a bloody legend! (that’s a really nice Aussie compliment).

Gregory Schier

Just fixed the whitespace issue in my dev branch

Gregory Schier

https://yaak.app/blog/2025.2.0-beta.1

Jamie CarlOP

Just tested the BETA and it’s working great now. Thanks!

Gregory Schier

Awesome, thanks for letting me know!

Daniel Lewis

I would still like a “JSON” option, too, because there’s a weird API I work with that wraps the JSON response in HTML code.

Gregory Schier
Daniel Lewis

Sorry, but I don’t see any of this in Version 2025.2.0 (20250520.152610).

Gregory Schier

Ah yes, there’s no explicit selector, just better auto detection. Did this not work for you?

Daniel Lewis

Unfortunately, it did not. Leading spaces are throwing off auto-detection, and there are some cases where the JSON is wrapped in HTML, so I need the ability to explicitly force the output to be interpreted as JSON in order to see the data prettied.

Daniel Lewis

Here’s an example:

curl -X GET 'https://itunes.apple.com/search' --url-query 'term=Audacity' --url-query 'country=us' --url-query 'media=podcast' --url-query 'limit=10'

Gregory Schier

I quickly added logic for this in 2025.2.2

For the HTML example, can you paste a text response here so I can see what it looks like? Formatting JSON within HTML will be more difficult.

Daniel Lewis

Here’s a thrown-together example:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JSON in Script Tag</title>
</head>
<body>
    <script>var myData = {"name":"John Doe","age":30,"city":"New York","hobbies":["reading","hiking","coding"]};</script>
</body>
</html>

Type to search feedback...