I have json
[
{
"name": "Name1",
"address": "City1\nCountry1"
},
{
"name": "Name2",
"address": "City2 Country2"
}
]
And I am using jayway library to extract "name" using "address". I want to parameterize the "address" using jpath
$.*[?(@.address=='{address}')].name
However, as you can see in json, first address has "\n" on it. Is there a way like normalize spacing for it so whenever I use jpath
$.*[?(@.address=='City1 Country1')].name
the value will still be extracted
A little late, a possible JSON-Path soltution is to use the contains operator for both parts:
However, this is not the same as a
==
comparison and could theoretically produce false positives.Another option is to use the regex filter
=~
. Using it gives you full control and the ability to only match what you want; since you have a newline we need to inline (?s) to make.*
match any character including newlines.