Search code examples
jsonpathjson-path-expression

JSONPath and regex: filter to search end substring


I need to extract "https://www.domain3.com" from this JSON

{
    "jobs": [
        {
            "name": "alfa",
            "url": "https://www.domain1.com"
        },
        {
            "name": "beta_publish",
            "url": "https://www.domain2.com"
        },
        {
            "name": "gammma_release",
            "url": "https://www.domain3.com"
        }
    ]
}

using a regular expression.

I'm trying to use this one (in https://www.jsonquerytool.com/ ...),

$..jobs[?(@.name=~/release*?/i)].url

but it doesn't work, but if I try to use it in https://regex101.com/ it seems to work fine.

Any suggestion will be appreciated!


Solution

    • Use match instead of =~

    JSONPath

    $.jobs[?(@.name.match(/release/i))].url
    

    enter image description here