# How to send a nested array through $\_GET or $\_POST

**URL:** <https://community.postman.com/t/how-to-send-a-nested-array-through-get-or-post/11995>\
**Category:** Help Hub\
**Tags:** variables\
**Created:** [April 16, 2020, 2:01pm UTC](https://community.postman.com/t/how-to-send-a-nested-array-through-get-or-post/11995 "2020-04-16T14:01:17Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![iansebryk](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/iansebryk/32/4251_2.png) [@iansebryk](https://community.postman.com/u/iansebryk)\
**Post date:** [April 16, 2020, 2:01pm UTC](https://community.postman.com/t/how-to-send-a-nested-array-through-get-or-post/11995/1 "2020-04-16T14:01:17Z")

</div>

i need to send a nested array through $\_GET or $\_POST. i can’t seem to figure out how to enter the data in the variable section. here’s a screenshot of what i have:

 ![postman-nested-array-woes-00](https://us1.discourse-cdn.com/getpostman/original/3X/7/2/72cd9d57820041ddde7a755a7064c9088b94f482.jpeg)

so how do i enter the array elements properly so they are recognized as an array and not a string. because that borks the code that relies on it being an array…

---

<div class="post-metadata">

**Author:** ![kinlane](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/kinlane/32/347_2.png) [@kinlane](https://community.postman.com/u/kinlane)\
**Post date:** [April 16, 2020, 4:05pm UTC](https://community.postman.com/t/how-to-send-a-nested-array-through-get-or-post/11995/2 "2020-04-16T16:05:33Z")

</div>

It looks like you are drying to make each array entry and object. I can’t see the whole thing, but I recommend trying {“id”:132421,“reportId”:“2927483”,"dCode:“EP0ee309”} --that would be value JSON for each directive array entry. Hope that helps.

---

<div class="post-metadata">

**Author:** ![iansebryk](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/iansebryk/32/4251_2.png) [@iansebryk](https://community.postman.com/u/iansebryk)\
**Post date:** [April 16, 2020, 5:03pm UTC](https://community.postman.com/t/how-to-send-a-nested-array-through-get-or-post/11995/3 "2020-04-16T17:03:29Z")

</div>

nope. still not working. i don’t know how to make this any clearer. i need a nested array. needs to look like this, because this is what the webapp itself is actually sending through $\_GET/$\_POST:

```javascript
discArray: {
  827422: {
    building_Name: "Palace of Doom",
    directives: {
      0: {
        id: 132421,
        reportID: "2927483",
        dCode: "EP0ss309",
        dInfo: "keep dry and free of water",
        dDue: "2020-05-14",
        ... &c.
      },
      1: {
        id: 132421,
        reportID: "2927483",
        dCode: "EP0ss309",
        dInfo: "keep dry and free of water",
        dDue: "2020-05-14",
        ... &c.
      },
    }
  }
}

```

so when i made the changes you suggested, i basically got the same thing again: just strings, not nested arrays:

 ![postman-nested-array-woes-01](https://us1.discourse-cdn.com/getpostman/original/3X/7/a/7ac6c7ee4ed2b87be9758c0eb53151276190f375.jpeg)

i hope this helps understand what i need a bit better. if not, please let me know. because if i’m stuck using one dimensional arrays, then this whole app is useless… and i doubt that’s the case. so i’m just needing to know how to give what it needs to do the job.

---

<div class="post-metadata">

**Author:** ![kevin.swiber](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/kevin.swiber/32/3820_2.png) [@kevin.swiber](https://community.postman.com/u/kevin.swiber)\
**Post date:** [April 16, 2020, 6:33pm UTC](https://community.postman.com/t/how-to-send-a-nested-array-through-get-or-post/11995/4 "2020-04-16T18:33:03Z")

</div>

Hi @iansebryk,

With PHP’s [`parse_str`](https://www.php.net/manual/en/function.parse-str.php), I think you’ll have to be a bit more verbose when setting the query params.

| Name | Value |
| --- | --- |
| `directives[0][id]` | 132421 |
| `directives[0][reportID]` | 2927483 |
| `directives[1][id]` | 132422 |
| `directives[1][reportID]` | 2927484 |

_EDIT: Alternatively, it might make more sense to add this with a pre-request script to reduce the manual work._

Hope that helps.

Best,

Kevin

---

<div class="post-metadata">

**Author:** ![iansebryk](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/iansebryk/32/4251_2.png) [@iansebryk](https://community.postman.com/u/iansebryk)\
**Post date:** [April 16, 2020, 8:15pm UTC](https://community.postman.com/t/how-to-send-a-nested-array-through-get-or-post/11995/5 "2020-04-16T20:15:15Z")

</div>

“pre-request script”… that’s what i need because the other way is flat out torture. is it something you can illustrate quickly, or do i need to spend an afternoon researching it on the website?

EDIT: found the ‘tutorial’. useless. have no idea what how the hell i’d send an array with it. at least i have a toe-hold. thank you.

---

<div class="post-metadata">

**Author:** ![kevin.swiber](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/kevin.swiber/32/3820_2.png) [@kevin.swiber](https://community.postman.com/u/kevin.swiber)\
**Post date:** [April 16, 2020, 8:36pm UTC](https://community.postman.com/t/how-to-send-a-nested-array-through-get-or-post/11995/6 "2020-04-16T20:36:20Z")

</div>

@iansebryk,

Here’s an example of how it might look.

```auto
const querystring = require('querystring');

const obj = {
    buildingName: "Palace of Doom",
    directives: [
        {
            id: 132421,
            reportID: "2927483",
            dCode: "EP0ss309",
            dInfo: "keep dry and free of water",
            dDue: "2020-05-14"
        },
        {
            id: 132421,
            reportID: "2927483",
            dCode: "EP0ss309",
            dInfo: "keep dry and free of water",
            dDue: "2020-05-14"
        },
    ]
};

const formatted = {
    buildingName: obj.buildingName
}

obj.directives.forEach((d, i) => {
    const topLevel = `directives[${i}]`;
    for (let [key, val] of Object.entries(d)) {
        formatted[`${topLevel}[${key}]`] = val;
    }
});

const qs = querystring.stringify(formatted)
pm.request.addQueryParams(qs);

```

You can import the collection with this URL: [https://www.getpostman.com/collections/e0da4ab4f566c1e65355](https://www.getpostman.com/collections/e0da4ab4f566c1e65355)

Best,

Kevin

---

<div class="post-metadata">

**Author:** ![iansebryk](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/iansebryk/32/4251_2.png) [@iansebryk](https://community.postman.com/u/iansebryk)\
**Post date:** [April 16, 2020, 10:06pm UTC](https://community.postman.com/t/how-to-send-a-nested-array-through-get-or-post/11995/7 "2020-04-16T22:06:40Z")

</div>

whoa. that’s a hell of a lot of code to just import a nested array! thank you for taking time out of your day to do that for me! O\_o where did you find the info to build that thing? i couldn’t find anything of depth or use on the website.

---

<div class="post-metadata">

**Author:** ![kevin.swiber](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/kevin.swiber/32/3820_2.png) [@kevin.swiber](https://community.postman.com/u/kevin.swiber)\
**Post date:** [April 16, 2020, 10:24pm UTC](https://community.postman.com/t/how-to-send-a-nested-array-through-get-or-post/11995/8 "2020-04-16T22:24:27Z")

</div>

The issue is that Node.js doesn’t stringify nested arrays/objects the same way PHP does. So there’s a dozen lines of code or so to do that.

We could lighten the weight of the code a bit, but it requires pulling in another Node.js module, `qs`. Pulling in external modules can add a layer of complexity, so I try to solve issues with built-in functionality first. (See this template: [Browserify CDN modules](https://explore.postman.com/templates/7170/browserify-cdn-modules).)

Here’s what the code would look like with the `qs` module:

```auto
new Function(pm.variables.get('init'))(pm);

const obj = {
    buildingName: "Palace of Doom",
    directives: [
        {
            id: 132421,
            reportID: "2927483",
            dCode: "EP0ss309",
            dInfo: "keep dry and free of water",
            dDue: "2020-05-14"
        },
        {
            id: 132421,
            reportID: "2927483",
            dCode: "EP0ss309",
            dInfo: "keep dry and free of water",
            dDue: "2020-05-14"
        },
    ]
};

const qs = require('qs');
pm.request.addQueryParams(qs.stringify(obj));

```

Here’s the same collection, except using the `qs` module: [https://www.getpostman.com/collections/367fad795a1296793f23](https://www.getpostman.com/collections/367fad795a1296793f23)

---

<div class="post-metadata">

**Author:** ![iansebryk](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/iansebryk/32/4251_2.png) [@iansebryk](https://community.postman.com/u/iansebryk)\
**Post date:** [April 16, 2020, 10:35pm UTC](https://community.postman.com/t/how-to-send-a-nested-array-through-get-or-post/11995/9 "2020-04-16T22:35:56Z")

</div>

gotcha. as much as i bitch and moan about this, i do appreciate your help learning this tool. long day and frustration has me tetchy and looking for simple solutions… 😛 so thanks again for your patient instruction. just when i think i know a tool… oh look. more. 😃 my biggest concern now, is where to find this information because, as i mentioned earlier, i found none of this on the website.

---

<div class="post-metadata">

**Author:** ![andrew.eames](https://avatars.discourse-cdn.com/v4/letter/a/b782af/32.png) [@andrew.eames](https://community.postman.com/u/andrew.eames)\
**Post date:** [October 16, 2020, 6:50am UTC](https://community.postman.com/t/how-to-send-a-nested-array-through-get-or-post/11995/10 "2020-10-16T06:50:34Z")

</div>

Did you manage to get this to work?  
I also have a nested array that I want to send through using a data file.
