Huachao / vscode-restclient

REST Client Extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=humao.rest-client
MIT License
5.31k stars 444 forks source link

json body is support multi-line data? #1158

Open lone1y-51 opened 1 year ago

lone1y-51 commented 1 year ago

my api body is json but some json field has multi-line, like this

{
     "describe": """1. this is first line
2. this is second line
""",
    "key": "this is key"
}

but this style cant post

a690700752 commented 1 year ago

try this? { "describe": "1. this is first line\n2. this is second line", "key": "this is key" }

gerritgriebel commented 3 months ago

ChatGPT gave the same answer. When insisting with "That's fine, but I want to avoid having to insert \n manually and rest client should do this for me" it responded:

To include multiline text in the VS Code REST Client plugin without manually inserting \n characters, you can use triple quotes (""") to allow the plugin to handle newlines automatically. This feature makes the request body more readable, especially for longer texts. Here's an example:

POST https://example.com/api/endpoint
Content-Type: application/json

{
  "message": """
  This is the first line.
  This is the second line.
  This is the third line.
  """
}

When you use triple quotes, the REST Client will automatically convert the multiline text into a single-line string with \n characters where the newlines are in your input. This simplifies writing and maintaining requests with multiline text.

Probably it read this feature request... :) I'd love to define variables in that manner with long texts copy pasted.