0

I have below JSON String. I need some help with writing a Jayway JsonPath expression that gets assignees for a specific role, say "Editor":

{
  "assignments": [
    {
      "role": {
        "label": "Editor",
        "id": "8bc3e27aafe310001fc933216b890910"
      },
      "assignees": [
        {
          "label": "user 1",
          "id": "bd76276f5e5344e4b27f8600c9000726"
        },
        {
          "label": "user 2",
          "id": "abbb210550af1017329208ee8632618c"
        }
      ]
    },
    {
      "role": {
        "label": "Owner",
        "id": "8bc3e27aafe310001fc932f0d928090f"
      },
      "assignees": [
        {
          "label": "user 3",
          "id": "3db5d9e1081e470bb98d5a3d15b67180"
        },
        {
          "label": "user 4",
          "id": "586e403c186c01521f763b5d4d0e6000"
        }
      ]
    },
    {
      "role": {
        "label": "Viewer",
        "id": "8bc3e27aafe310001fc9333ecccf0911"
      },
      "assignees": [
        {
          "label": "user 5",
          "id": "9bdfa0b60668100b619f393cfc282340"
        },
        {
          "label": "user 6",
          "id": "586e403c186c018f6c8d798c4e0e6a00"
        }
      ]
    }
  ]
}

2 Answers 2

1

Assuming you're using XPath 3.1 which is the first version to provide XPath access to JSON data, you can write

assignments[?role?label = 'Editor']?assignees
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the response. @michael. I am using Jayway 2.4
Then I guess you're probably wanting a JsonPath solution rather than XPath.
0

I figured the answer

$.assignments[?(@.role.id=='8bc3e27aafe310001fc933216b890910')].assignees

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.