如何在Postman中传递Swagger定义的复杂结构字段?
values Parameter in Postman for Your Swagger API Hey there! Let's walk through exactly how to handle that nested values parameter you're working with. First, let's clarify the structure you're dealing with—it's a nested JSON object, not just a random long string, so we need to make sure Postman sends it in the right format.
Case 1: Parameter is in the Request Body (Most Common for POST/PUT)
If your Swagger defines this as part of the request body (which is typical for create/update operations), follow these steps:
- Open your request in Postman and switch to the Body tab.
- Select the raw option, then choose JSON from the dropdown menu next to it.
- Paste the full JSON structure into the editor—make sure it's properly formatted like this:
{ "values": { "date": { "date": "2021-01-15", "time": "12:30am" } } } - Double-check that the
Content-Typeheader is set toapplication/json(Postman will add this automatically when you select the JSON raw format, but it never hurts to verify!).
Case 2: Parameter is a Query Parameter (Less Common)
If your Swagger specifies this as a query parameter (unlikely for nested objects, but possible), you'll need to pass it as a URL-encoded JSON string:
- Go to the Params tab in Postman.
- Add a new parameter with the key
values. - For the value, paste the nested JSON as a single string:
{"date":{"date":"2021-01-15","time":"12:30am"}} - Postman will automatically URL-encode this string for you when sending the request, so you don't have to do that manually.
Pro Tip
If you haven't already, import your Swagger document directly into Postman (via the Import button, selecting your Swagger JSON/YAML file). Postman will generate pre-built request templates with all the fields mapped out—you just need to fill in the values for date and time in the appropriate nested fields, which eliminates the chance of formatting errors.
内容的提问来源于stack exchange,提问作者mstdmstd

