filter the Json according to string in an array in JSONPATH

前端 未结 3 1760
春和景丽
春和景丽 2021-01-15 10:39

I have a situation where I have json String that has a child as Array that contains only Strings. Is there as way I can get the object reference of the arrays that contains

3条回答
  •  無奈伤痛
    2021-01-15 11:21

    Assuming you are using Goessner JSONPath (http://goessner.net/articles/JsonPath/) the following should work:

    $.Books.History[?(@.Tags.indexOf('Indian') != -1)]
    

    According to the Goessner site, you can use underlying JavaScript inside the ?() filter. You can therefore use the JavaScript indexOf function to check if your Tags array contains the tag 'Indian'.

    See a working example here using this JSONPath query tester: http://www.jsonquerytool.com/sample/jsonpathfilterbyarraycontents

提交回复
热议问题