2

I'm using a data file for past man with the following JSON with the following data

{
    "FirstName": "Jennifer",
    "MiddleName": "Geraldine",
    "LastName": "Gemma",
    "email": "montes.nascetur@vulputatenisisem.net"
    "Phone":[{"Number":"55-(622)813-5953"},{"Number":"233-(935)372-8021"}]}
}

I'm attempting to do a post with the following data variables in RAW

{
    "FirstName": "{{FirstName}}",
    "MiddleName": "{{MiddleName}}",
    "LastName": "{{LastName}}",
    "email": "{{email}}",
    "Phone": {{Phone}}
}

All the data is being populated with the exception of the "Phone". {{Phone}} is not be substituted.

Is there a way of doing this or an alternative way of posting a JSON request?

OR

Is there an alternative way of posting this information in JSON using Postman from a data file?

Avijit Karmakar
  • 8,890
  • 6
  • 44
  • 59
Mark Anderson
  • 21
  • 1
  • 3

2 Answers2

2

You can use the Pre-req. tab of your request to enter JavaScript code. There you can iterate through the array data.Phone and stringify each entry in the array, JSON.stringify, and construct a concatenated string (say phone_numbers). Then you can set this value to a variable:

postman.setGlobalVariable("phone_nos", phone_numbers). 

This "phone_nos" variable can then be referenced in the RAW request body.

"Phone" : {{phone_nos}}
Clíodhna
  • 818
  • 1
  • 15
  • 29
1

You can convert an array into a string as shown below in the data file.

{
   "FirstName": "Jennifer",
   "MiddleName": "Geraldine",
   "LastName": "Gemma",
   "email": "montes.nascetur@vulputatenisisem.net",
   "Phone": "[{\"Number\":\"55-(622)813-5953\"},{\"Number\":\"233-(935)372-8021\"}]}"
}
RNGesus.exe
  • 205
  • 1
  • 12