0

I've a requirement to fetch value from json using jayway jsonpath.

Json structure looks like below

[
  {
    "type": "a",
    "values": [
      {
        "name": "a",
        "value": [1,2,3]
      },
      {
        "name": "b",
        "value": [3,4,5]
      },
      {
        "name": "c",
        "value": [6,7,8]
      }
    ]
  }
]

my requirement is in the values array if the name value is a and value array contains value 1, then I need to fetch value array where name is b.

I have written jsonPath expression like below

$..values[?(@.name == 'a')]

where it is returning only

{
  "name": "a",
  "value": [1,2,3]
}

could someone help me in writing jsonpath expression please , Thanks in advance.

expected output

[3,4,5]

tried with

$..[?(@.values[?(@.name== 'a' && @.value CONTAINS 1)])]

then it is matching every object present in root array.

2
  • Can you please include the expected output in JSON format? Commented Jan 3, 2022 at 10:14
  • JSON Path isn't going to do this for you because it doesn't have conditionals that operate iteratively. You need a programmed solution. Commented Jan 3, 2022 at 11:07

1 Answer 1

1

With Jayway JSONPATH you might get lucky with below jsonpath

$..[?(@.values[?(@.name=='a')].value[*] contains 1 )].values[?(@.name=='b')].value[*]
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.