Search code examples
jsonata

Pick specific value if Array Contains a Specific String - JSONata


Struggling to pick the email value for role "Developer" using JSONata expression. The below expression return the value as true but not sure how can i pick the email field value for that specific list.

("Developer" in (.roles))**

{  
  "demo": [
    {
      "contacts": [
        
        {
          "email": "test1@abc.com",
          "name": "test1",
          "roles": [
            "admin"
          ]
        },
        {
          "email": "test2@abc.com",
          "name": "test1",
          "roles": [
            "HR"
          ]
        },
        {
          "email": "test3@abc.com",
          "roles": [
            "Developer"
          ]
        }
      ]
    }
  ]
}

Solution

  • demo.contacts["Developer" in roles].email
    

    See https://try.jsonata.org/Uq3gN04Af