是否可以使用JSONPath或XPath获取查询字符串?

问题描述 投票:0回答:1

我目前正在使用Insomnia App创建一些请求,并且我的API响应之一是带有“ redirect_uri”字段的JSON,该值实际上是一个URL。

我需要获取only the code parameter,因此在以下示例中,JSONPath或XPath需要返回8748d39f-1d4f-311f-92c6-4b279db1b317

{
  "redirect_uri": "http://www.google.com?state=string&code=8748d39f-1d4f-311f-92c6-4b279db1b317"
}

返回值:8748d39f-1d4f-311f-92c6-4b279db1b317

JSONPath或XPath是否可能?

rest xpath oauth jsonpath insomnia
1个回答
0
投票

您可以使用这个有点复杂的xpath表达式来做到这一点:

substring-before(substring-after('{
  "redirect_uri": "http://www.google.com?state=string&code=8748d39f-1d4f-311f-92c6-4b279db1b317"
}',
'code='),'"')
© www.soinside.com 2019 - 2024. All rights reserved.