# Retrieve string value in array from an response

**URL:** <https://community.postman.com/t/retrieve-string-value-in-array-from-an-response/61301>\
**Category:** Help Hub\
**Tags:** variables, json, response, array\
**Created:** [May 21, 2024, 5:51pm UTC](https://community.postman.com/t/retrieve-string-value-in-array-from-an-response/61301 "2024-05-21T17:51:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anita.christobel](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@anita.christobel](https://community.postman.com/u/anita.christobel)\
**Post date:** [May 21, 2024, 5:51pm UTC](https://community.postman.com/t/retrieve-string-value-in-array-from-an-response/61301/1 "2024-05-21T17:51:56Z")

</div>

Below is the response for my request

```auto
{
  "code": 401,
  "reason": "Unauthorized",
  "detail": {
    "failureUrl": "{\"code\":403,\"reason\":\"Forbidden\",\"message\":\"Policy validation failed\",\"detail\":{\"result\":false,\"failedPolicyRequirements\":[{\"policyRequirements\":[{\"policyRequirement\":\"VALID_NAME_FORMAT\"}],\"property\":\"givenName\"}]}}"
  }
}

```

I need to verify `{\"policyRequirement\":\"VALID_NAME_FORMAT\"}` policyRequirement value. I am not able to achieve it array.

Can you please help

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [May 22, 2024, 2:00pm UTC](https://community.postman.com/t/retrieve-string-value-in-array-from-an-response/61301/2 "2024-05-22T14:00:04Z")

</div>

The failureUrl key is a stringified object, so you will need to parse it before you can access the elements within.

The value for failedPolicyRequirements is an array with a single object in it and so is the policyRequirements key that sits just underneath.

The following should target the policyRequirement key.

```auto
const response = pm.response.json()

let failureUrl = JSON.parse(response.detail.failureUrl);

let policyRequirement = failureUrl.detail.failedPolicyRequirements[0].policyRequirements[0].policyRequirement

pm.test("policyRequirement = VALID_NAME_FORMAT", () => {
    pm.expect(policyRequirement).to.eql("VALID_NAME_FORMAT");
});

```

---

<div class="post-metadata">

**Author:** ![anita.christobel](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@anita.christobel](https://community.postman.com/u/anita.christobel)\
**Post date:** [May 22, 2024, 2:57pm UTC](https://community.postman.com/t/retrieve-string-value-in-array-from-an-response/61301/3 "2024-05-22T14:57:09Z")

</div>

> [@michaelderekjones](#):
>
> ```auto
> const response = pm.response.json()
> 
> let failureUrl = JSON.parse(response.detail.failureUrl);
> 
> let policyRequirement = failureUrl.detail.failedPolicyRequirements[0].policyRequirements[0].policyRequirement
> 
> pm.test("policyRequirement = VALID_NAME_FORMAT", () => {
> pm.expect(policyRequirement).to.eql("VALID_NAME_FORMAT");
> });
> 
> ```

Thank you @michaelderekjones It works

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [June 21, 2024, 2:57pm UTC](https://community.postman.com/t/retrieve-string-value-in-array-from-an-response/61301/4 "2024-06-21T14:57:52Z")

</div>

Closed on June 21, 2024, 2:57pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
