Trouble with Nested JSON in Postman Data Templating

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:

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

Expected Response:

    "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:

    "message": "Hello {{$body ''}} from {{$body ''}} (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.

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.

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.

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. I’ll really appreciate it if you could do that.

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!.

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

Here is the correct link to make a bug report.

Thank You! @gbadebo-bello

1 Like

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