使用json路径从json中提取值

时间:2017-04-18 07:40:32

标签: json path expression jsonpath

我尝试根据以下json中的电子邮件值提取id值:

[
{"id":11,"username":"John","address":"London","email":"john@test.com"},
{"id":12,"username":"Piere","address":"Paris","email":"piere@test.com"},
{"id":13,"username":"Anne","address":"Moscow","email":"anne@test.com"},
]

我的表达是

$..[?(@.email=='anne@test.com')].id

它不起作用。这个表达有什么问题?

1 个答案:

答案 0 :(得分:1)

你的表情是正确的。我认为您需要更正您的JSON数据。存在语法错误。 这是正确的:

[
{"id":11,"username":"John","address":"London","email":"john@test.com"},
{"id":12,"username":"Piere","address":"Paris","email":"piere@test.com"},
{"id":13,"username":"Anne","address":"Moscow","email":"anne@test.com"}
]

您可以使用它来下次验证您的JSON。

https://jsonformatter.curiousconcept.com/

您也可以在此处验证您的表达

http://jsonpath.com/

Json validator