Javascript 在Postman中导入外部库
我的需要: 我想在JSON响应上构建一个包含过滤器的路径Javascript 在Postman中导入外部库,javascript,node.js,json,postman,jsonpath,Javascript,Node.js,Json,Postman,Jsonpath,我的需要: 我想在JSON响应上构建一个包含过滤器的路径 //Simple path - OK response.Node1.Node2.Node3.Node4 //Path with list - OK response.Node1.Node2.Node3[1].Node4 //Path with condition (filter) - NOK response.Node1.Node2[?(@.Node3 == 'value')].Node3bis Postman不理解[?(@.Nod
//Simple path - OK
response.Node1.Node2.Node3.Node4
//Path with list - OK
response.Node1.Node2.Node3[1].Node4
//Path with condition (filter) - NOK
response.Node1.Node2[?(@.Node3 == 'value')].Node3bis
Postman不理解[?(@.Node3=='value')]语法,因为本机不支持jsonPath
因此,我试图在Postman中导入jsonPath js库,我发现了两个:
研究
- 我已经读过了,没有一个答案能满足我的需要
- Postman js代码仅限于
- 邮递员把图书馆限制在公共场所
- 有一个(检查提示#5)将js代码添加为全局变量,并在请求中调用它。然而,它不适用于jsonPath项目,因为它不仅仅是一个简单的函数,而是一个完整的项目。我尝试了许多不同的方法,但仍然无法从Postman测试中调用jsonPath函数
- 我也读了这本书
- 来自GitHub社区,被关闭以支持。它已经关闭,以支持。自2015年6月以来,在没有明确答案的情况下开放(只有上面提到的小技巧)
未知域 即使我阅读了它们的全球使用情况,我也不知道关于NodeJs/NPM/Newman的任何技术知识 但我读到postman支持NodeJs,允许生成NodeJs代码片段,并且我看到可以使用NodeJs导入jsonPath库 也许可以从那里做点什么,但我没有专业知识让它发生
问题: 有人知道如何使它完全起作用吗 我的意思是,找到一种使用jsonPath表达式的方法,多亏了postman中的jsonPath js库。。。 请帮忙
欢迎使用任何postman集合:)。关于最初的问题,导入外部js代码目前不受支持(上面显示的全局变量技巧除外),但postman团队目前正在开发。 如果使用该版本,您可以在正式交付之前获得它 关于我的需求,我实际上找到了一种方法,使用cheerio构建带有条件的路径。 注意:ResponseBook是XML格式的,因此我会加载cheerio
var $ = cheerio.load(responseBody, {
ignoreWhitespace: true,
xmlMode: true
});
//Will show in the console the value of NODE3bis corresponding to a NODE3='value'
console.log("cheerio xpath with condition: " +
$('NODE1 > NODE2 > NODE3:contains("value")')
.parent().find('NODE3bis').text());
//Where NODE3 and NODE3bis are sibling.
//Another way to write it using .has() function, which allows to avoid the use of .parent() afterward:
console.log("cheerio xpath with condition: " +
$('NODE1 > NODE2').has('NODE3:contains("value")').find('NODE3bis').text());