Sending an array of objects as form-data

How can I send an array of objects as form-data?

I send something similar but with raw json like this:

{
    "quiz":[{
        "question": "what is the correct answer of 2 + 2: ",
        "type": 0,
        "answer": [
            {
                "name": "2"
            },
            {
                "name": "3"
            },
            {
                "name": "5"
            },
            {
                "name": "4"
            },
            {
                "name": "10"
            }
        ]
    }]
}

The type means the type of the awser i’ll have in my frontend
0 = radio buttons
1 = text fields

I try this in raw but i need to send it in form-data, any ideas?.

To add an array in the “Form Data” section of a Postman request, follow these steps:

  1. Select the request type as “POST” or “PUT”
  2. Go to the “Body” tab and select “form-data” as the body type
  3. Click on the “key” field and enter the name of the array, with square brackets “” appended to the end (e.g. “myArray”)
  4. Click on the “value” field and enter the values of the array, separated by commas (e.g. “value1, value2, value3”)
  5. Repeat step 3-4 for each element you want to add to the array
  6. Send the request

Note: if you want to send an array in the query parameters, you can simply add the array name in the url and separate the values by commas.

answer[0].name = 2
answer[1].name = 3
answer[2].name = 5
answer[3].name = 4
answer[4].name = 10

Not sure its that easy, and I’m also not sure based on that JSON that this can be sent as form data.

I would need to see the API specification to make that assumption.

On face value, what we have is a JSON object with top level key called Quiz that contains an array.

The Quiz array has three key value pairs called “question”, “type” and “answer”.

The value for the answer key is also an array.

Therefore which array do you store in the form-data. Is it the whole of the Quiz array, or is it the answer key. The array may need to be stringified before posting which is a common pattern for this type of request.

This question is over a year old, so I’m not really expecting the original poster to provide the API spec that would be needed to answer the question properly.

This doesn’t work at all

1 Like