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

Raw body editor JSON comment #3358

Closed
horacehylee opened this issue Aug 8, 2017 · 125 comments
Closed

Raw body editor JSON comment #3358

horacehylee opened this issue Aug 8, 2017 · 125 comments

Comments

@horacehylee
Copy link

It would be great if request raw body editor can support comment, for easier testing

@prashantagarwal
Copy link

@horacehylee You can add comments to raw body. Can you explain a bit more about the use case you are trying to achieve.

@prashantagarwal prashantagarwal self-assigned this Aug 8, 2017
@prashantagarwal prashantagarwal added the support How do I ... ? Can I ... ? label Aug 8, 2017
@horacehylee
Copy link
Author

@prashantagarwal Yes, we can add comments to raw body. But it shows red error highlight for JSON.
postman_json

Can we have a similar syntax highlight as in Javascript.
postman_json_2

@abhijitkane
Copy link
Member

@horacehylee The JSON schema (http://www.json.org/) does not support comments. Postman supports disabling parameters for form-data / urlencoded types, but cannot do so for JSON - the entire body is treated as the request payload.

@davmrv
Copy link

davmrv commented Dec 1, 2017

@abhijitkane yeah, but this is a testing tool, not a JSON validator, commenting out JSON could be a great tool for testing APIs, because is a pain to send many information using the form-data / urlencoded tool

@M00nk1d
Copy link

M00nk1d commented Mar 1, 2018

@abhijitkane I completely agree with @Bl4ckf4ll It would be a greate feature to allow comments in JSON editor.

@thirtified
Copy link

Still open as #3117.

@markus-ethur
Copy link

Agree totaly, we should have some kind of comments

@ykh
Copy link

ykh commented Sep 22, 2018

I need this one also 👍

@NaveenThiyagarajan
Copy link

+1 It would be great if we have this feature.

@Ben-Mark
Copy link

+1 A must feature

@arekgotfryd
Copy link

+1 Would be great to have this feature

@YuliaLoyko
Copy link

+1 looking for it as well

@kid1412621
Copy link

+10086

@arthurlauck
Copy link

Must implement

@a85 a85 reopened this Dec 7, 2018
@numaanashraf numaanashraf added feature and removed support How do I ... ? Can I ... ? labels Dec 7, 2018
@z3ugma
Copy link

z3ugma commented Dec 14, 2018

+1

4 similar comments
@FeChagas
Copy link

FeChagas commented Jan 9, 2019

+1

@pbindy
Copy link

pbindy commented Jan 17, 2019

+1

@chunkai-meng
Copy link

+1

@julienloizelet
Copy link

+1

@Nicolai6120
Copy link

Nicolai6120 commented Feb 1, 2019

You can trim all comments before sending JSON data, you just provide the handy way to present addditional information for new API users, who will use this method. Like some kind of specification. It can be separated field, but showed on screen at the same time with JSON data. Yeah, we have a @comments@ link at the right top corner, but it is absolutely not convinient!

Look what we have in swagger:
image

@Dikushi
Copy link

Dikushi commented Feb 11, 2019

+1

2 similar comments
@carlnoval
Copy link

+1

@spooks7er
Copy link

+1

@prashantagarwal prashantagarwal removed their assignment Mar 7, 2019
@silverjohnes
Copy link

I'm using this script as my pre-request script to remove comments in raw json data, and it's kinda works.

Could you be so king to show me how you mark comments?

@AkariMarisa
Copy link

@silverjohnes
2021-04-20_08-48
2021-04-20_08-51
2021-04-20_08-50
I use folder as a container to manage APIs, so I can add a 'root' pre-request script to rid off the comments.
I only test raw json data, and it's works for me. Maybe someday someone can improve this method.
ps. Please ignore the Chinese that on the pictures.

@julienloizelet
Copy link

I'm using this script as my pre-request script to remove comments in raw json data, and it's kinda works.

var rawData = pm.request.body.raw
var strippedData = rawData.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, (m, g) => g ? "" : m)
console.info(strippedData)
pm.request.body.raw = strippedData

I tried this but it failed (unfortunately): the logged data is ok but it seems that the body sent remains unchanged.
Maybe I'm doing something wrong but I found an issue related to this : #4808
When I read this issue, I understand that changing the body request in a pre-request script is not possible. @AkariMarisa : what is your secret ?

@AkariMarisa
Copy link

@julienloizelet You're right, my method doesn't change the JSON. I thought it worked because my testing server can reformat JSON data, and forgot this. I'm trying to figure out why postman's pre-request script cannot update body.

@codenirvana
Copy link
Member

codenirvana commented Apr 26, 2021

Hello everyone 👋

To temporarily unblock this, Postman v8.3.0 added support for programmatically mutating the request body.
So, the workaround suggested by @AkariMarisa will work now. 🎉

The following pre-request script will remove comments from the raw mode body.

// Strip JSON Comments
if (pm.request.body.mode === 'raw') {
    const rawData = pm.request.body.toString();
    const strippedData = rawData.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, (m, g) => g ? "" : m)

    pm.request.body.raw = strippedData;
}

Also, we'll soon add native support for this in the app.

@ilya-git
Copy link

ilya-git commented May 5, 2021

The code above changes Content-Type to text/plain, if you API does not accept that one can add something like this:

pm.request.headers.add({key: 'Content-Type', value: 'application/json'});

to fix it. There is probably a simpler way but I did not figure it out.

@gooza
Copy link

gooza commented May 21, 2021

To uncomment the lines i use find "//" and replace in selection. It is anoying but better than comment out line by line.

@LuckyTil
Copy link

LuckyTil commented Oct 28, 2021

JSON text.
Ctrl-K, Ctrl-U uncomments current line OK, when block is not selected.
When block is selected, Ctrl-K, Ctrl-U uncomments block and UPCASES it.
Fix, please.

@rr-justin-hanselman
Copy link

+1 to this feature. For complicated legacy systems, I have the hardest time helping my QAs and new developers understand all the permutations of a payload.

Bloating the pre-request scripts would only further add confusion.

@asoltesz
Copy link

+1 to this feature, badly needed.

In Postman, there is no good feature to document the request, so everybody would like to do it in the body.

The Documentation panel is mostly useless. Is is very hard to notice / read anything you put in there because it displays a lot of other contents which is not about documenting the request.

The Comments panel can only be used with Workspaces (which is a non-starter for us).

@mayureshs
Copy link

+1 to this feature. Please fix the uppercasing issue.

@Kyreikal
Copy link

Kyreikal commented Nov 3, 2022

+1 to this.

The form data ui would be perfect for this. Add a new raw-json tab and just have it spit out the raw json on selected variables rather than form data. Everything you need is there, type, description, key and value. Only thing that would need work is nested fields.

You can document and optionally select variables with a click.

@emiliogarza
Copy link

Why refuse a feature that clearly many people want? @Kyreikal has a good solution here ^

@AceOubahaTLI
Copy link

+1 please fix uppercasing, it makes the uncomment feature more or less unusable

@seanc
Copy link

seanc commented Dec 28, 2022

+1 for this feature

@PeterRygeMCB
Copy link

+1

1 similar comment
@Geet2312
Copy link

+1

@giridharvc7 giridharvc7 self-assigned this Jan 31, 2023
@codenirvana codenirvana changed the title Feature request: Raw body editor JSON comment Raw body editor JSON comment Feb 20, 2023
@codenirvana codenirvana self-assigned this Feb 20, 2023
@Martin-Suska
Copy link

JSON text. Ctrl-K, Ctrl-U uncomments current line OK, when block is not selected. When block is selected, Ctrl-K, Ctrl-U uncomments block and UPCASES it. Fix, please.

I'm using CTRL + / to comment/uncomment, works fine in Postman 10.10.8

@ashuvyaspm45
Copy link

Hello everyone 👋
Thank you for your patience for this feature. We have added the comment support in raw json body editor in latest release (Postman v10.13). Please check this out and give us the feedback.

@SamehSaeed
Copy link

SamehSaeed commented Jun 16, 2024

The issue has returned "Postman v11.2.0" when using Ctrl+k+u to un-comment while selecting the text, the text transforming to uppercase after une-commented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests