Aster
Aster

Reputation: 233

jsonpath expression for value match

Hi I have this test data

data = [
  {
      "company" : "abc",
      "CEO" : "john"
  },
  {
      "company" : "xyz",
      "CEO" : "ron"
  }
]

I want to query data by "ron", and want to get

  {
      "company" : "xyz",
      "CEO" : "ron"
  }

I know in xpath I could write an expression //*[*="ron"] to get this, but not able to come up with similar jsonpath expression. Can someone help me with this?

Upvotes: 2

Views: 9033

Answers (2)

riyasvaliya
riyasvaliya

Reputation: 825

There are differences in the various JSONPath implementations. The expression $[?("ron" in @.*)] should give you what you want if using the Jayway (Java) implementation. Test here. Put the array without the data = in the input box.

Because the expression is indeterminate, it will always return a list i.e.

[
  {
    "company" : "xyz",
    "CEO" : "ron"
  }
]

Upvotes: 1

Andersson
Andersson

Reputation: 52675

Try this one and let me know whether it's the exactly result you want to get:

$.[?(@.CEO=="ron")]

Upvotes: 4

Related Questions