1

I am trying to find an object in a JSON array using JsonPath. Here is my JSON:

[
  {
    "bpm": "766",
    "time": "20:14:57",
    "confidence": "0"
  },
  {
    "bpm": "766",
    "time": "20:14:57",
    "confidence": "0"
  },
  {
    "bpm": "767",
    "time": "20:14:33",
    "confidence": "0"
  }
]

I am using SelectToken with the following JsonPath query to try to find a JSON object using two keys bpm and time. There is supposed to be an and operator between bpm and time.

Here is my query:

$.[?(@.bpm=='767',@.time=='20:14:33')]

But I'm getting an error saying there is an unexpected character , after '767'. What am I doing wrong?

1 Answer 1

1

In Newtonsoft's implementation of JsonPath, the and operator is a double ampersand &&, not a comma ,. Change your expression as shown below and it should work properly:

var array = JArray.Parse(json);
var obj = array.SelectToken("$.[?(@.bpm=='767' && @.time=='20:14:33')]");

Fiddle: https://dotnetfiddle.net/gpU56p

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.