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

req.getBody() returns string instead of JSON if body contains unquoted variable #4364

Open
2 of 4 tasks
TanguyP opened this issue Mar 28, 2025 · 0 comments
Open
2 of 4 tasks
Assignees
Labels
bug Something isn't working

Comments

@TanguyP
Copy link

TanguyP commented Mar 28, 2025

I have checked the following:

  • I have searched existing issues and found nothing related to my issue.

This bug is:

  • making Bruno unusable for me
  • slowing me down but I'm able to continue working
  • annoying

Bruno version

2.0.1

Operating System

Windows 11

Describe the bug

I have a request with a JSON body:

{"parent_foo_id": 123}

In my pre-request script, req.getBody() returns an object, as expected.
However, if I decide to use a variable:

{"parent_foo_id": {{foo_id}}}

then req.getBody() suddenly starts returning a string. This can be fixed by wrapping the variable in a string:

{"parent_foo_id": "{{foo_id}}"}

which is of course not necessarily safe, depending on how the target API works.

I understand the rationale behind returning a string: since Bruno doesn't interpolate variables before returning req.getBody(), the body with the unquoted, uninterpolated variable is not valid JSON (as can be seen in my second code block above, to which I didn't assign type "json" because it would highlight the incorrect syntax). Since it's not valid JSON, it can only be returned as a string.

That all makes perfect sense from a Bruno developer's point of view... but from my Bruno user's point of view, before diving into this, I absolutely did not expect the type to suddenly change just because I'm using a variable.

In my opinion, this is one more reason to start interpolating values by default in req.getBody() (and everywhere else), as requested for instance in issue #3752 :)
If that is done, then someone who explicitly requests the uninterpolated version of the body is more likely to be aware that it may not be parsable as JSON.

.bru file to reproduce the bug

Here's a collection demonstrating all 3 cases explained above (you have to use the environment, that's where the variable is defined)

test-req-body-type.zip

Screenshots/Live demo link

No screenshots

@TanguyP TanguyP added the bug Something isn't working label Mar 28, 2025
@sreelakshmi-bruno sreelakshmi-bruno self-assigned this Mar 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants