thunder-client-support
thunder-client-support copied to clipboard
Allow json with comment in request body
Is your feature request related to a problem? Please describe.
While developing it really useful to comment parts of a json request body, but currently there is no option that I could find to strip the comment before sending the request
Describe the solution you'd like
Ability to comment out part of a json request body
Describe alternatives you've considered
In postman I achieved something similar adding a script that filters the lines in the body starting with a comment before sending the request. I could not find any option to add a script to run before the request are sent so this solution is not currently possible
Implementation:
A simple implementation could support only single line comments // that are trivial to filter out, but since this is an extension of vscode it may be possible to leverage the parser implemented by vscode to support json with comments
Thanks @CaselIT for the feedback, will add to roadmap
I've tried using filters for this, and I can create the filtered body to send in the request, but there is no way that I could find of telling thunder client to use the updated body instead of the original one.
Replacing the value of tcType.request.body.raw does not work
Is there a way I've not found to use filters to support this functionality?
@CaselIT how you are replacing comments in the filter?
currently the request object is read-only, modifying it will have no effect.
@CaselIT how you are replacing comments in the filter?
currently the request object is read-only, modifying it will have no effect.
that's indeed what I'm asking. Filter can access the body, but have no way (that I could find) of returning an updated body
If you need to remove comments before sending request, we can do that in the extension, if that helps?
that would be really helpful, since when experimenting with an api it's very useful to comment part of the request to experiment with various inputs
Sure, What logic were you using to replace comments in filter?
A very banal
bodyStr = bodyStr.split('\n').filter(line => !line.trim().startsWith('//')).join('\n')
But it's probable that vscode offers something better already builtin, since it does support jsonc (json with comments) natively
Thanks will verify it.
I am not using vscode editor, it’s ace editor.
This feature is now implemented and published to marketplace, please update to v2.1.0
See all features released https://github.com/rangav/thunder-client-support/releases/tag/v2.1.0
Please let me know your feedback.
Limitations:
- Format button will not work with comments
- In Body tab it will still show error
When you run request, the extension will remove comments and send body
I've tried it and it seems to work. The limitations are a bit of a pain, but better than nothing. Thanks for implementing this change!
I will research for any better library, that can do format, remove comments and support bigInt, when I have am free.
I found this library https://github.com/kaelzhang/node-comment-json, but does not support bigInt (large numbers)