# Pm.response.json() - Response as Object

**URL:** <https://community.postman.com/t/pm-response-json-response-as-object/10417>\
**Category:** Help Hub\
**Created:** [January 29, 2020, 12:27pm UTC](https://community.postman.com/t/pm-response-json-response-as-object/10417 "2020-01-29T12:27:13Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![srk.groups](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@srk.groups](https://community.postman.com/u/srk.groups)\
**Post date:** [January 29, 2020, 12:27pm UTC](https://community.postman.com/t/pm-response-json-response-as-object/10417/1 "2020-01-29T12:27:13Z")

</div>

Hi Experts,

I want to bring dynamicity when parsing through the API response received. To achieve that, trying to pass the Key to the object and get the value, which is achievable with javascript.

My response body:

```
{
   "name":{
      "title":"string",
      "forename":"string",
      "mid_initial":"string",
      "surname":"string",
      "suffix":"string"
   }
}

```

Theoretically, I should be able to get “John” with

```
var jsonData = pm.response.json();

var x = jsonData["name.title"];

```

however, this is not happening as expected; can someone give me an expertise suggestion.

Maybe I am not parsing the response body; how can I get response body alone from pm.response

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [January 29, 2020, 1:54pm UTC](https://community.postman.com/t/pm-response-json-response-as-object/10417/2 "2020-01-29T13:54:15Z")

</div>

Hey @srk.groups,

Welcome to the community! 🚀

It looks like you using both bracket and dot notion in the same line.

You should be able to use either of these to get the value from the object.

```
var x = jsonData["name"]["title"];

var x = jsonData.name.title;   

```

However, if your response was something like this:

```
{
   "name.title":"string"
}

```

Then your syntax would be correct as that would be the correct way to access that keys value.

Hope that helps. 🙂

---

<div class="post-metadata">

**Author:** ![srk.groups](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@srk.groups](https://community.postman.com/u/srk.groups)\
**Post date:** [January 29, 2020, 1:58pm UTC](https://community.postman.com/t/pm-response-json-response-as-object/10417/3 "2020-01-29T13:58:58Z")

</div>

Thank you for the comments @danny-dainton

was trying to do something like this

pm.expect(jsonData[“ **name.title** ”]).to.eql(pm.iterationData.get(“ **name.title** ”))

Is there some sort of possibility; as “name.title” will be passed as a header from csv.

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [January 29, 2020, 2:07pm UTC](https://community.postman.com/t/pm-response-json-response-as-object/10417/4 "2020-01-29T14:07:08Z")

</div>

That should work fine with a CSV data file in the runner.

```
pm.test("Basic Test", function () {
    pm.expect(jsonData.name.title).to.equal(pm.iterationData.get("name.title"));
});

```

If the column header is `name.title` is will pick up that reference and use the value from that in the assertion.

---

<div class="post-metadata">

**Author:** ![srk.groups](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@srk.groups](https://community.postman.com/u/srk.groups)\
**Post date:** [January 29, 2020, 2:18pm UTC](https://community.postman.com/t/pm-response-json-response-as-object/10417/5 "2020-01-29T14:18:17Z")

</div>

@danny-dainton

yes that will work; the ultimate goal is to iterate multiple columns from csv - i am still in research mode.

For that part it the solution will not work:-pm.expect(jsonData.name.title).to.equal(pm.iterationData.get(“name.title”)

say,  
csv holds:  
name.title,name.firstname,name.lastname  
mr.,someone,somewhere

in this i am trying to bring in the dynamicity; 🙂

2 things here i want o achieve,

1. Iterate through column of csv,
2. Set object property dynamically

Example:  
1st iteration of the loop  
pm.expect(jsonData[“ **name.title** ”]).to.eql(pm.iterationData.get(“ **name.title** ”))

2nd iteration of the loop  
pm.expect(jsonData[“ **name.firstname** ”]).to.eql(pm.iterationData.get(“ **name.firstname** ”))

3rd iteration of the loop  
pm.expect(jsonData[“ **name.lastname** ”]).to.eql(pm.iterationData.get(“ **name.lastname** ”))

if your can provide me some direction, that would be a help

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [January 29, 2020, 2:47pm UTC](https://community.postman.com/t/pm-response-json-response-as-object/10417/6 "2020-01-29T14:47:32Z")

</div>

Can you add some images or what you have so far, just so I can understand how far you’ve got and what’s not working?

If I understand correctly, is this what you’re trying to do?

I’ve just set your response data as a variable inside the `Tests` script but it would work the same if you use `pm.response.json()`. Each request in the collection has a single test, to compare the _response_ data with the data in the CSV file.

```
name.title,name.firstname,name.lastname
mr,someone,somewhere

```

 ![Screenshot 2020-01-29 at 14.40.49](https://us1.discourse-cdn.com/getpostman/original/3X/0/3/03057be0bccbde0d79290103140e4f6d4b78d58e.png)

If this isn’t what you were trying to do, could you share the structure of your collection, please?

---

<div class="post-metadata">

**Author:** ![srk.groups](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@srk.groups](https://community.postman.com/u/srk.groups)\
**Post date:** [January 30, 2020, 5:42am UTC](https://community.postman.com/t/pm-response-json-response-as-object/10417/7 "2020-01-30T05:42:22Z")

</div>

@danny-dainton

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/6/9/69b7fa7800f556b512bb23c872946b94cbc8f119.png)

Commented part is a prototyping of what i want to achieve; sample csv also attached the “DrillDownToResponse” is a boolean operator which pivots whether i need to drill down into response details or not.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/2/f/2f8e77f45c6a9d59d2dfdbcfe964284a6053660a.png)

---

<div class="post-metadata">

**Author:** ![srk.groups](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@srk.groups](https://community.postman.com/u/srk.groups)\
**Post date:** [February 3, 2020, 5:19am UTC](https://community.postman.com/t/pm-response-json-response-as-object/10417/8 "2020-02-03T05:19:20Z")

</div>

@danny-dainton and Team - can you give me some direction on this.

---

<div class="post-metadata">

**Author:** ![terand1967](https://avatars.discourse-cdn.com/v4/letter/t/bc8723/32.png) [@terand1967](https://community.postman.com/u/terand1967)\
**Post date:** [January 22, 2021, 3:51pm UTC](https://community.postman.com/t/pm-response-json-response-as-object/10417/9 "2021-01-22T15:51:58Z")

</div>

What’s the syntax to dereference the json object properties from within an array, like this? I keep getting this: AssertionError: expected undefined to deeply equal ‘478-89-5114’

Using this test:

```auto
pm.test("t_SSNCheck", function () {
    var jsonData = pm.response.json();
    pm.expect(jsonData["ssn"]).to.eql("478-89-5114"); //{{eSSN}} = pm.environment.get("eSSN")
});

```

```auto
[
    {
        "orderId": 38590863,
        "ssn": "478-89-5114"
    }
]

```

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [January 22, 2021, 4:08pm UTC](https://community.postman.com/t/pm-response-json-response-as-object/10417/10 "2021-01-22T16:08:46Z")

</div>

Hey @terand1967

It looks like you would need something like this:

```auto
pm.test("t_SSNCheck", function () {
    var jsonData = pm.response.json();
    pm.expect(jsonData[0].ssn).to.eql(pm.environment.get("eSSN"));
});

```

---

<div class="post-metadata">

**Author:** ![terand1967](https://avatars.discourse-cdn.com/v4/letter/t/bc8723/32.png) [@terand1967](https://community.postman.com/u/terand1967)\
**Post date:** [January 22, 2021, 4:29pm UTC](https://community.postman.com/t/pm-response-json-response-as-object/10417/11 "2021-01-22T16:29:33Z")

</div>

Cool, thanks…that should work. Not enough coffee today… J

---

<div class="post-metadata">

**Author:** ![aerospace-astronaut3](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@aerospace-astronaut3](https://community.postman.com/u/aerospace-astronaut3)\
**Post date:** [May 6, 2021, 1:19am UTC](https://community.postman.com/t/pm-response-json-response-as-object/10417/12 "2021-05-06T01:19:12Z")

</div>

Thank you! I had that issue too 🙂

---

<div class="post-metadata">

**Author:** ![spacecraft-operator8](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@spacecraft-operator8](https://community.postman.com/u/spacecraft-operator8)\
**Post date:** [June 15, 2023, 9:25am UTC](https://community.postman.com/t/pm-response-json-response-as-object/10417/13 "2023-06-15T09:25:45Z")

</div>

Any idea for issue:

In after response script i add:

let jsonData1 = pm.response.json();

In run time i receive Error:  
TypeError: pm.response.json is not a function.

Also tried:  
let jsonData2 = pm.response.messages.json();  
Then jsonData2 is Undefined.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/2/a/2a3721d76909a08878fdf78e035ef1e58871b60e.png)

---

<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:** [June 15, 2023, 2:39pm UTC](https://community.postman.com/t/pm-response-json-response-as-object/10417/14 "2023-06-15T14:39:49Z")

</div>

@spacecraft-operator8

This should probably be its own question.

This is a gRPC request\response and you don’t need to parse those , so pm.response.json() will error.

Please take a look at the following which has examples of working with the response elements.

[Testing gRPC APIs with Postman | Postman Blog](https://blog.postman.com/testing-grpc-apis-with-postman/)

---

<div class="post-metadata">

**Author:** ![raniakanksha22](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@raniakanksha22](https://community.postman.com/u/raniakanksha22)\
**Post date:** [March 8, 2025, 1:24pm UTC](https://community.postman.com/t/pm-response-json-response-as-object/10417/15 "2025-03-08T13:24:27Z")

</div>

Hi @srk.groups ,

Have you solved this issue ? i want to achieve similar result

Example:  
1st iteration of the loop - want to validate  
pm.expect(jsonData[“ **name** ”]).to.eql(pm.iterationData.get(“ **name** ”))

2nd iteration of the loop- want to validate  
pm.expect(jsonData[“ **name.firstname** ”]).to.eql(pm.iterationData.get(“ **name.firstname** ”))

3rd iteration of the loop  
pm.expect(jsonData[“ **name.firstname.lastname** ”]).to.eql(pm.iterationData.get(“ **name.firstname.lastname** ”))
