JSONPath expression to look inside different keys

我的未来我决定 提交于 2019-12-13 19:18:49

问题


I have a JSON returned by a RESTful API:

{
    "0": {
        "id": "1484763",
        "name": "Name",
        "values": {
            "0": {
                "value": "Peter"
            }
        }
    },
    "1": {
        "id": "2584763",
        "name": "phone",
        "values": {
            "0": {
                "value": "45456456"
            }
        }
    }
}

How do I write a JSONPath that extracts a phone number value? (so in this case, "45456456"). What makes the problem harder, phone number object is not always inside "1" key.


回答1:


Try this JsonPath which results in phone number 45456456

$..[?(@.name = 'phone')].values.0.value

Basically, you have to apply a filter ?() where name == 'phone' and then use normal json path.

Try the expression in this link

JsonPath expression syntax can be found here.



来源:https://stackoverflow.com/questions/33048100/jsonpath-expression-to-look-inside-different-keys

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!