Skip to content

Remove escaped whitespace characters from JSON bodies, in request code generator #5832

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

Open
JP-from-Postman opened this issue Jan 25, 2019 · 9 comments

Comments

@JP-from-Postman
Copy link

[User feedback, submitted by Postman Support]

Please read through the guidelines before creating a new issue.

Describe the bug
For some languages, the Generate Code Snippets tool includes newlines (\n) and tabs (\t) for JSON request body strings. User feedback is that these may be superfluous, and can be omitted from code generation. See screenshot below:

screen shot 2019-01-25 at 10 34 29 am

To Reproduce
Steps to reproduce the behavior:

  1. Create a new request
  2. Add a JSON body, (example below)

screen shot 2019-01-25 at 10 45 52 am

3. Open Code Generator for request, select a language where \n and \t show up:
  • C (LibCurl)
  • C# (RestSharp)
  • Go
  • Java OK HTTP
  • Java Unirest
  • JavaScript Jquery AJAX
  • (Others)
  1. Find request body string in generated code, see \n and \b escaped characters

Expected behavior
Newline and tab characters for JSON body strings these languages could be omitted (?

App information (please complete the following information):

  • App Type: Native
  • Postman Version: 6.7.1
  • OS: Linux, Mac, (guessing Windows as well)
@JP-from-Postman JP-from-Postman changed the title Remove escaped characters from JSON bodies, in request code generator Remove escaped whitespace characters from JSON bodies, in request code generator Jan 25, 2019
@Lucretiel
Copy link

Lucretiel commented Jan 25, 2019

Relatedly: in languages that have "heavy" or "raw" strings like Go (``), Rust (r#" "#), and Python (''' '''), prefer to use those strings, so as to reduce the escaped double quotes in the JSON body.

@ryparker
Copy link

This is affecting our documentation through postman as well.

@abhijitkane abhijitkane added feature and removed bug labels Jul 15, 2019
@stcalica
Copy link

user reports this is an issue as well.

@JP-from-Postman
Copy link
Author

It looks like this is still affecting documentation. Since the bug is still open, can it be addressed here?

@webholik
Copy link

I have created two PRs to fix this issue in Javascript/Nodejs and Python codegens.
Use proper indentation for JSON bodies in Javascript and Nodejs codegens
Use json.dumps in Python codegens if Content-Type is JSON

@umeshp7
Copy link

umeshp7 commented Jul 15, 2021

Hey @JP-from-Postman @stcalica @ryparker @Lucretiel !!

We have made some fixes around unwanted characters in JS/Node and Python codegens as mentioned above. Could you please try the latest version postman app and see if you still face these issues?

@ariellevi
Copy link

ariellevi commented Jul 15, 2021

Thank you the fixes are working grate , did you continue to another language like C#?

@hillsydev
Copy link

Hi, this problem is still happening in version 8.10.0.

JSON body content in C# code includes new line characters in the code snippet. If I change the code snippet from C# - RestSharp to cURL, then the JSON content will be formatted correctly, without new line characters. This also affects the Postman documentation examples.

Screenshot 2021-08-17 113820

@Avdhesh-Varshney
Copy link

I'm facing a similar indentation problem while writing my API documentation.

Image

Is there any solution of it?

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

No branches or pull requests