0

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!

1 Answer 1

1

Use this JsonPath just putting an extra dot after $

$..[?(@.Name=='attr1')]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.