Find a JSON property name that starts with something using JSON Path

前端 未结 2 799
感动是毒
感动是毒 2020-12-18 22:35

Is it possible to find a property name that matches a regex pattern (or at least starts with) using JSON Path. In XPath I can use name() but I

相关标签:
2条回答
  • 2020-12-18 22:40

    Useful to someone else
    You can use regular expression using =~ left matches regular expression. For more in formation visit https://github.com/jayway/JsonPath

    [?(@.name =~ /foo.*?/i)]
    
    0 讨论(0)
  • 2020-12-18 23:06

    From my googling this is not possible in standard json path. However, the jsonpath-plus package extends the specification with @path; and makes the following possible

    $..[?(@path.includes("[\'x-"))]
    $..*[?(@property === 'price' && @ !== 8.95)]
    

    The above assumes you are using ES6.

    0 讨论(0)
提交回复
热议问题