如何将变量从 JSON 传递到邮递员正文 [英] How to pass variables from JSON to postman body

查看:13
本文介绍了如何将变量从 JSON 传递到邮递员正文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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?

解决方案

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.

这篇关于如何将变量从 JSON 传递到邮递员正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆