【发布时间】:2019-07-11 23:25:06
【问题描述】:
我的需要: 我想在我的 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 不理解 [?(@.Node3 == 'value')] 语法,因为原生不支持 jsonPath。
因此,我尝试在 Postman 中导入 jsonPath js 库,我发现了两个:
研究
我已经阅读了this post,但没有一个答案能满足我的需求。
Postman js 代码仅限于sandbox。
Postman 将库限制为 this list。
有一个trick(检查提示#5)添加js代码作为全局变量,并在请求中调用它。但是它不适用于 jsonPath 项目,因为它不仅仅是一个简单的函数,而是一个完整的项目。我尝试了很多不同的方法,但仍然无法从我的 Postman 测试中调用 jsonPath 函数。
我还阅读了related Postman issue。
来自 GitHub 社区,this issue 已关闭以支持 this one。已关闭以支持this one。自 2015 年 6 月以来一直没有明确答案(只是上面提到的小技巧)。
未知域
即使我阅读了它们的全球使用情况,我对 NodeJs / NPM / Newman 的技术一无所知。
但我读到 postman 支持 NodeJs,允许生成 NodeJs 代码 sn-p,我看到可以使用 NodeJs 导入 jsonPath 库。
也许可以从那里做一些事情,但我没有专业知识来实现它。
问题:
有谁知道如何让它完全发挥作用?
我的意思是,在邮递员中找到一种使用 jsonPath 表达式的方法,这要感谢 jsonPath js 库... 请帮忙。
欢迎任何使其工作的邮递员收藏:)。
【问题讨论】:
标签: javascript node.js json postman jsonpath