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

Is it possible to use JSONPath or XPath to get a query string?

我目前正在使用 Insomnia App 创建一些请求和我的一个 API 响应 我得到一个 JSON 和 "redirect_uri" 字段,值实际上是一个 URL.

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

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

return 的值:8748d39f-1d4f-311f-92c6-4b279db1b317

是否可以使用 JSONPath 或 XPath?

您可以使用这个有点复杂的 xpath 表达式来完成:

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