# Trouble with Nested JSON in Postman Data Templating

**URL:** <https://community.postman.com/t/trouble-with-nested-json-in-postman-data-templating/58649>\
**Category:** Help Hub\
**Tags:** tests, variables, collections, json, api\
**Created:** [March 9, 2024, 10:57am UTC](https://community.postman.com/t/trouble-with-nested-json-in-postman-data-templating/58649 "2024-03-09T10:57:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lunar-module-geosci7](https://avatars.discourse-cdn.com/v4/letter/l/90db22/32.png) [@lunar-module-geosci7](https://community.postman.com/u/lunar-module-geosci7)\
**Post date:** [March 9, 2024, 10:57am UTC](https://community.postman.com/t/trouble-with-nested-json-in-postman-data-templating/58649/1 "2024-03-09T10:57:40Z")

</div>

I’m encountering difficulties with Postman’s data templating feature when dealing with nested JSON structures in mock responses. Let me demonstrate the issue with a simple example:

**Request Body:**

```auto
{
    "person": {
        "name": "Alice",
        "age": 25,
        "address": {
            "city": "Los Angeles",
            "zipcode": "90001"
        }
    }
}

```

**Expected Response:**

```auto
{
    "message": "Hello Alice from Los Angeles (Zipcode: 90001)! You are 25 years old."
}

```

I’ve tried using the `{{$body '...'}}` syntax to reference the values from the nested JSON structure in the response template, but it doesn’t seem to work as expected. Instead, I’m getting placeholders in the response like:

```auto
{
    "message": "Hello {{$body 'person.name'}} from {{$body 'person.address.city'}} (Zipcode: {{$body 'person.address.zipcode'}})! You are {{$body 'person.age'}} years old."
}

```

Has anyone encountered a similar issue with Postman’s data templating when dealing with nested JSON structures?

How can I correctly reference nested values from the request body in the response template?

Any advice or insights would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![gbadebo-bello](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gbadebo-bello/32/12175_2.png) [@gbadebo-bello](https://community.postman.com/u/gbadebo-bello)\
**Post date:** [March 11, 2024, 2:49pm UTC](https://community.postman.com/t/trouble-with-nested-json-in-postman-data-templating/58649/2 "2024-03-11T14:49:27Z")

</div>

Hi @lunar-module-geosci7.

Welcome to the Postman Community!

I am unable to replicate this issue on my end. Can you share a screenshot of your workbench, showing your request body and the response you’re getting? and a screenshot of your sample response showing how you added the templates? Feel free to obscur any personal or sensitive data from the screenshots.

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

---

<div class="post-metadata">

**Author:** ![lunar-module-geosci7](https://avatars.discourse-cdn.com/v4/letter/l/90db22/32.png) [@lunar-module-geosci7](https://community.postman.com/u/lunar-module-geosci7)\
**Post date:** [March 12, 2024, 7:16am UTC](https://community.postman.com/t/trouble-with-nested-json-in-postman-data-templating/58649/3 "2024-03-12T07:16:30Z")

</div>

Hey @gbadebo-bello  
Thank You, for Responding for this Issue,  
I have shared some of snapshots to understand the problem clearly,  
if you see in this, if there is any nested content and when you try to use it in response template the values are empty in response but is you try calling outer key its perfectly working, but  
as in case of “hobby” key which is ln the list as nested content. and in response the value is empty.

 ![Screenshot 2024-03-12 124125](https://us1.discourse-cdn.com/getpostman/original/3X/1/2/12ee0b0dc041d23ab527e5fae7fbb6e40a2d07c8.jpeg)  
 ![Screenshot 2024-03-12 124211](https://us1.discourse-cdn.com/getpostman/original/3X/6/8/68383c22b68d22ecb0062e26b422eb579f883b88.jpeg)

---

<div class="post-metadata">

**Author:** ![gbadebo-bello](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gbadebo-bello/32/12175_2.png) [@gbadebo-bello](https://community.postman.com/u/gbadebo-bello)\
**Post date:** [March 12, 2024, 1:55pm UTC](https://community.postman.com/t/trouble-with-nested-json-in-postman-data-templating/58649/4 "2024-03-12T13:55:15Z")

</div>

Hi @lunar-module-geosci7.

I’m able to replicate this. It appears the issue only happens when working with an arrays. Would you mind making a bug report [here](https://github.com/postmanlabs/postman-app-support/issues/new?assignees=&labels=&projects=&template=Bug_report.yml). I’ll really appreciate it if you could do that.

---

<div class="post-metadata">

**Author:** ![lunar-module-geosci7](https://avatars.discourse-cdn.com/v4/letter/l/90db22/32.png) [@lunar-module-geosci7](https://community.postman.com/u/lunar-module-geosci7)\
**Post date:** [March 13, 2024, 6:00am UTC](https://community.postman.com/t/trouble-with-nested-json-in-postman-data-templating/58649/5 "2024-03-13T06:00:19Z")

</div>

Hi @gbadebo-bello  
Thank You for checking out this Issue,  
Sure I’ll report this Bug.  
can you please tell me where can I report this ?  
The Link which you gave me is not working for me.

Thank You!.

---

<div class="post-metadata">

**Author:** ![gbadebo-bello](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gbadebo-bello/32/12175_2.png) [@gbadebo-bello](https://community.postman.com/u/gbadebo-bello)\
**Post date:** [March 13, 2024, 3:15pm UTC](https://community.postman.com/t/trouble-with-nested-json-in-postman-data-templating/58649/6 "2024-03-13T15:15:05Z")

</div>

Hi, @lunar-module-geosci7. Sorry about that.

[Here is the correct link](https://github.com/postmanlabs/postman-app-support/issues/new?assignees=&labels=&projects=&template=Bug_report.yml) to make a bug report.

---

<div class="post-metadata">

**Author:** ![lunar-module-geosci7](https://avatars.discourse-cdn.com/v4/letter/l/90db22/32.png) [@lunar-module-geosci7](https://community.postman.com/u/lunar-module-geosci7)\
**Post date:** [March 14, 2024, 6:42am UTC](https://community.postman.com/t/trouble-with-nested-json-in-postman-data-templating/58649/7 "2024-03-14T06:42:08Z")

</div>

Thank You! @gbadebo-bello

---

<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:** [April 13, 2024, 6:42am UTC](https://community.postman.com/t/trouble-with-nested-json-in-postman-data-templating/58649/8 "2024-04-13T06:42:44Z")

</div>

Closed on April 13, 2024, 6:42am UTC

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