How to pass variables from JSON to postman body

纵饮孤独 提交于 2020-04-13 04:40:06

问题


I want to parameterized my tests in Postman. This is the example body of POST request:

{
  "entity_id": "{{entity_id}}",
  "text": data.comment_name
}

entity_id is global variable and it works correctly, but I want to set value of text from JSON file. data.comment_name doesn't work it saved me exactly data.comment_name as text variable. I want to include this JSON file with all variables in collection runner. How can I do that?


回答1:


If your data file looks something like this JSON example:

[
    {
        "entity_id": 1,
        "comment_name": "This is my comment_name"
    }
]

To reference the values in the file, the POST body needs to look like this:

This is how your example would be but you don't need to add the " " around the variable. This could cause issues if the value is a number and adding the quotes around the value in the request body, would make this a string and possibly lead to a bad request.



来源:https://stackoverflow.com/questions/48164223/how-to-pass-variables-from-json-to-postman-body

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!