usebruno / bruno

Opensource IDE For Exploring and Testing Api's (lightweight alternative to postman/insomnia)
https://www.usebruno.com/
MIT License
22.09k stars 1.04k forks source link

JSON duplicate keys are modified on send #2360

Open lapo-luchini opened 1 month ago

lapo-luchini commented 1 month ago

I have checked the following:

Describe the bug

When trying to send an incorrect JSON with duplicate keys I would either expect that Bruno does check the value and highlights the problem, or that Bruno does no checks and send the value as is. What I instead can see is that the JSON value is mangled by overwriting the duplicate value.

.bru file to reproduce the bug

meta {
  name: Test JSON
  type: http
  seq: 2
}

post {
  url: https://echo.zuplo.io
  body: json
  auth: none
}

body:json {
  {
    "a": 1,
    "b": 2,
    "b": 3
  }
}

Screenshots/Live demo link

image

lapo-luchini commented 1 month ago

image

sibansal commented 1 month ago

That is the way JSON parser works, it will replace the key/value pair with last updated pair while parsing JSON.

If you need to use JSON with duplicate key/value pair you might need to look around for customized implementation of parser or need to use regex.

That is not recommended actually.

Just in case you need duplicate key/value pair in your app, it would be better to assign list of values to the key, instead of duplicate pairs.

I have attached a small code snippet, hope it helps 😌

image

jwetzell commented 3 weeks ago

@sanjai0py @lohxt1 this can probably be closed unless bruno plans on implementing JSON parsing any differently.

lohxt1 commented 3 weeks ago

there is draft pr that addresses this issue