Create nested array with json object with form-data

Hello there.

For a couple of days now, I try to create a nested array and have an object inside that array where I can set text key/value pairs while simultaneously uploading files (hence form-data).

In the end, I want the following object: {media: [{media: file, type: video}, {media: file1, type: photo]}

The way I tried to achieve this, and which I still think should be the way to go:

media[0][type]:photo
media[0][media]:file
media[1][type]:video
media[1][media]:file1

but this doesnt end up as an array.

Maybe you are missing some JavaScript basics.

You create an array like this:

const a = [];

Add add items like this:

a.push({media: "file", type: "video"})

It should be:

media.0.media
media.0.type
media.1.media
media.1.type

so the array is at the first media.
I recently found the same issue and hope this would help anyone facing the same problem after 2023.

it should be that the array is defined with […] while non array element are using dot.
so in your case, the first media is array.
so it should be :

media[0].type : photo
media[0].media : file 
media[1].type : video
media[1].media : file 

there might be a case where the array is deeply nested, but the pattern should be the same. array using bracket and non array using dot

e.g you have something like this

{upload :{media: [{media: file, type: video}, {media: file1, type: photo]}}

then it should be like this if using form-data as the postman body

upload.media[0].type : photo
upload.media[0].media : file 
upload.media[1].type : video
upload.media[1].media : file