ks099
ks099

Reputation: 103

Extracing value from json using json path

I've tried to extract the id value based on email value from the following json:

[
{"id":11,"username":"John","address":"London","email":"[email protected]"},
{"id":12,"username":"Piere","address":"Paris","email":"[email protected]"},
{"id":13,"username":"Anne","address":"Moscow","email":"[email protected]"},
]

My expression is

$..[?(@.email=='[email protected]')].id

It doesn't work. What is wrong with this expression?

Upvotes: 0

Views: 78

Answers (1)

Amin Husni
Amin Husni

Reputation: 147

Your expression is correct. I think you need to correct your JSON data instead. There is a syntax error. This is the correct one:

[
{"id":11,"username":"John","address":"London","email":"[email protected]"},
{"id":12,"username":"Piere","address":"Paris","email":"[email protected]"},
{"id":13,"username":"Anne","address":"Moscow","email":"[email protected]"}
]

You can use this to validate your JSON first next time.

https://jsonformatter.curiousconcept.com/

You may also validate your expression here

http://jsonpath.com/

Json validator

Upvotes: 1

Related Questions