I have a json like this
{
"Attributes": [
{
"Name": "attr1",
"Value": "abcd"
},
{
"Name": "attr2",
"Value": "abcde"
},
{
"Name": "attr3",
"Value": "abcdef"
}
],
"SomeObject": {
"Attributes": [
{
"Name": "attr1",
"Value": "xyz"
},
{
"Name": "attr2",
"Value": "xyza"
},
{
"Name": "attr3",
"Value": "wxyxz"
}
]
}
}
I am implementing a common code. Every time the object structure may change, But the attributes structure is going to remain same. I want find all the attributes by matching their name like Name=="attr1". I read about JsonPath. I am using Json.net(Newtonsoft) library for json manipulation. I came acros this -> JObject.SelectTokens(jsonPath)
. I created one json path query as $.[?(@.Name=='attr1')]
and tested at http://jsonpath.com/ . It is working properly but in c# code it is giving me null results. Can anyone please suggest me a solution, your help is appreaciated!
Use this JsonPath just putting an extra dot after $