3

I have a JSONArray within a JSONArray, I want to apply JSONPath expression on this in such a way that i get JSONObject or JSONArray as a result when a condition is satsified on the inner JSONArray.

Eg:

{
  "A": [
    {
      "B": [
        {
          "id": 1
        },
        {
          "id": 2
        },
        {
          "id": 3
        }
      ],
      "C": {
        "id": 10,
        "name": "PQR"
      },
      "id": 25,
      "name": "XYZ"
    },
    {
      "B": [
        {
          "id": 4
        },
        {
          "id": 5
        },
        {
          "id": 6
        }
      ],
      "C": {
        "id": 15,
        "name": "PQR"
      },
      "id": 20,
      "name": "XYZ"
    }
  ]
}

if i want all elements of A where C.id = 10, I would use: $.A[?(@.C.id == 10)]

Now, What predicate is to be used to obtain all the objects within A, where B.id = 1? Note: B is an array of JSON objects.

1 Answer 1

1

I had success with $.A[?(@.B[?(@.id == 1)])]

but only when using Scala's Gatling implementation: http://jsonpath.herokuapp.com/

The Jayway implementation seems to totally ignore the inner filter and according to an issue on their GitHub, that's a bug.

Sign up to request clarification or add additional context in comments.

2 Comments

You're right, With Gatling it did work for me. But i am using the Jayway library, Are you sure its a limitation?
@VishalMahuli updated the answer, it looks like a bug.

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.