How to add nested arrays and objects in the postman body via form-data
A simple guide about how you can add array values or object values in the postman body while a post/put request along with adding files
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 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
Hope this has helped you! and solved your problem. If you have any questions let me know in the comments section.