10

I need to send parameters as array of objects in POSTMAN.

"array": [
    {"field1": "html", "field2": "5"},
    {"field1": "css", "field2": "3"}
 ]

I know that array must send as array[] but how can I set one item of the array as an object?

I tried this

"array[]" : "{"field1": "html", "field2": "5"}" 

But I'm getting a 500 response error.

Xan
  • 74,770
  • 16
  • 179
  • 206
Vyacheslav
  • 612
  • 1
  • 9
  • 17
  • possible duplicate of [Postman chrome extension with array of hashes as value](http://stackoverflow.com/questions/24239042/postman-chrome-extension-with-array-of-hashes-as-value) – Xan Jul 30 '14 at 11:04
  • @Xan Thank you for respond. I've tried to use: array[0][field1] html array[0][field2] 5 But got error 500 – Vyacheslav Jul 30 '14 at 13:52
  • I think it will help for u
    https://stackoverflow.com/questions/12756688/is-it-possible-to-send-an-array-with-the-postman-chrome-extension
    – suresh Jun 02 '17 at 12:20

5 Answers5

10

enter image description hereJust send it in raw format(in json) and specify data type as application/json. Worked for me

Taimoor Changaiz
  • 10,250
  • 4
  • 49
  • 53
deb2fast
  • 990
  • 11
  • 18
  • Yep, it could be used also – Vyacheslav Nov 18 '16 at 21:31
  • 2
    The requirement is to send the data as form-data and not with raw data. The reason behind this: To support existing code. If you know how I can send this data in form-data then please let me know. – Zubin Shah Dec 03 '19 at 05:04
10

If array of arrays works for you as well, you can send them like this:

enter image description here

gradosevic
  • 4,809
  • 2
  • 36
  • 51
1

Go to bulk edit

userdata:[{"name":"name1","email":"email1@gmail.com"},{"name":"name2","email":"email2@gmail.com"},{"name":"name3","email":"email3@gmail.com"}]
0

I found the solution adding raw data as JSON. from body > raw

[
  {
    "text": "Buy fish",
    "completed": true
  },
  {
    "text": "Go for walk check",
    "completed": false
  },
  {
    "text": "Pick baby from school",
    "completed": false
  }
]
Siful Islam
  • 1,906
  • 3
  • 21
  • 31
0

I know this ia an old post but this might help someone out there.... it's what worked for me:

In your controller: (Laravel/PHP)

$validator = Validator::make($request->all(), [
'fields' => 'nullable|array|min:1',
'fields.key1.*' => 'integer',
'fields.key2.*' => 'integer'
]);

if ($validator->fails())
{
return ...
}

Then in Postman:

fields[0]['key1']
fields[0]['key2']

.... and you can repeat this as many times as you need to, just increment the index

fields[1]['key1']
fields[1]['key2']

If you dd(fields) in your controller, you'd get:

0 => [
      key1 => value1
      key2 => value2
]

1 => [
      key1 => value3
      key2 => value4
]

.....

Cedric
  • 45
  • 1
  • 4