'How to filter below JSON based on the specific values in JSON expression or using Java?
I want to filter the below JSON based on value of en-US key like Template1 or Template2
[
{
"en-US": "Template1"
},
{
"en-US": "Template2"
},
{
"en-US": "Template2"
},
{
"en-US": "Template2"
},
{
"en-US": "Template1"
},
{
"en-US": "Template1"
},
{
"en-US": "Template1"
},
{
"en-US": "Template2"
},
]
I have tried with below JSON expression but it didn't work.
$[?(@.en-US=='Template1')]
Solution 1:[1]
I'm not sure which library you're using. But the following expression works in https://json-everything.net/json-path
$[?(@['en-US']=='Template1')]
The issue seems to be that json path frameworks don't like properties with dashes in the name. Using the [''] syntax was the only way I've found to circumvent that.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pavel Ronin |
