I have a JSON that structured as below. I am using JSONPath Expression to filter values only. How does one filter and output only those values where the first three characters of those values match with a given three characters.
[
{
"firstName": "John",
"lastName": "doe",
"age": 26,
"address": {
"streetAddress": "naist street",
"city": "Nara",
"postalCode": "630-0192"
},
"phoneNumbers": [
{
"model": "iPhone",
"number": "0123-4567-8888"
},
{
"model": "iPhoneX",
"number": "0123-4567-8910"
}
]
},
{
"firstName": "Ram",
"lastName": "Pavan",
"age": 29,
"address": {
"streetAddress": "Delhi street",
"city": "Noid",
"postalCode": "222-211"
},
"phoneNumbers": [
{
"model": "iPhone 6S",
"number": "43212-888-9998"
},
{
"model": "iPhone 14",
"number": "84848-337-83330"
}
]
}
]
In the above sample JSON, I was successful in filtering all values that has model
as the key using this JSONPath expression:
$..model
The output was as expected a list of all models:
[
"iPhone",
"Samsung",
"iPhone 6S",
"iPhone 14"
]
That was fine, but then if I had to filter only those values that starts with (begins with) a given set of characters iph
or iPhone
then how does one write the expression. The desired output in this case should be as follows:
[
"iPhone",
"iPhone 6S",
"iPhone 14"
]