How to add nested arrays and objects in the postman body via form-data

UsamaUsama
2 min read

Table of contents

Hi there, Welcome here.

Usually, in form-data in postman, we write the data into key-value pairs. Like in the first column we write the key and then its value in the next column, I am ignoring other columns here. And users who are new to postman might not know how they can put arrays and objects in postman's body along with files via form-data.

Here I am giving you a very simple explanation about how you can add array values or object values in the postman body while a post/put request along with adding files.

For Arrays:

  • If you need to add files, you can change the key type to 'file' by hovering the key field you will see a dropdown on its right side.

  • After adding the necessary files, you can either switch the key-value to text format by clicking on the bulk-edit button which is located in the upper right corner of the form, or remain in the key-value format as default and add the necessary fields as follows.

What I want to add:

records: [
    {
      title: "Boom! you go here.",
      id: "b2bf14f60c00635a"
     },
    {
      title: "HAHA! you go here.",
      id: "b2bf14f60c00636b"
     }
  ]

This is how I will add in the postman body

array[index][property-name] : value

records[0][title]:Boom! you go here.
records[0][id]:b2bf14f60c00635a

records[1][title]:HAHA! you go here.
records[1][id]:b2bf14f60c00636b

for arrays postman form data.png For nested array you would do this:

posts: [
    {
      title: "Boom! you go here.",
      id: "b2bf14f60c00635a",
      links:[ 
              {
                href: "https://usamaadev.vercel.app"
               }
          ]
     },
  ]

posts[0][links][0][href]:https://usamaadev.vercel.app/#projects.

For Objects:

  • Same as above, If you need to add files, you can change the key type to 'file' by hovering the key field you will see a dropdown on its right side.

What I want to add:

parents: {
    main: {
      title: "Boom! you go here.",
      id: "b2bf14f60c00635a"
     },
    sub: {
      title: "HAHA! you go here.",
      id: "b2bf14f60c00636b"
     }
  }

This is how I will add in the postman body, unlike above, instead of an array index you will have to put object property.

parents[main][title]:Boom! you go here.
parents[main][id]:b2bf14f60c00635a

parents[sub][title]:HAHA! you go here.
parents[sub][id]:b2bf14f60c00636b

objects postman.png

Hope this has helped you! and solved your problem. If you have any questions let me know in the comments section.

0
Subscribe to my newsletter

Read articles from Usama directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Usama
Usama

Hello! I'm Usama, a Software Developer based in Lahore, PK. With over two years of experience working with designers, developers and programmers, I consider myself a collaborative, solution-oriented software developer. Using my technical support experience to identify and solve complex problems is something I have enjoyed in my current role.