0

I have a POST request in which the data comes as JSON. For testing via collection runner, I want to pick those from JSON File but I am unable to define variables in Array and am stuck need support. Input data is like: Input Data:

{
    "field1": "1",
    "field2": "111111111111111",
    "field3": "value3",
    "field4": [
        [],
        [],
        []
    ],
    "master_field": {
        "field5": 11,
        "field6": 33.0,
        "field7": [5, 184]
    },
    "field8": [
        [10, 6, -1030],
        [-83, 0, -999],
        [-54, 21, -1054],
        [-162, 21, -990]
    ],
    "field9": 92
}

I tried making a request in POSTMAN Body like JSON, it worked till field3 only:

{
"field1": "{{field1}}",
"field2": "{{field2}}",
"field3": "{{field3}}",
"field4": 
[
"{{field4}}"
]
}

It Doesn't parse field4 onward. Thanks

  • Does this answer your question? [Extract value from array of objects in Postman](https://stackoverflow.com/questions/42257293/extract-value-from-array-of-objects-in-postman) – Henke Feb 02 '21 at 15:53
  • Or this [Postman: Can i save JSON objects to environment variable so as to chain it for another request?](https://stackoverflow.com/q/41479494) – Henke Feb 02 '21 at 16:55

1 Answers1

0

In order to store arrays in Postman variables, you have to stringify them. Say your field4 value is an array in your test script, just JSON.stringify() it and save it in the environment variable.

Then you can use the variable directly in your request body.

{
  "field1": "{{field1}}",
  "field2": "{{field2}}",
  "field3": "{{field3}}",
  "field4": {{field4}}
}

Note that the field4 variable is NOT inside quotes.

  • Hello Thanks for your response. However, "field4": [[a,b],[c,d],[e,f]] has array of array. If I define as "field4":{{field4]}}, then the data is getting sent as "field4": a,b,c,d. It should be sent as "field4": [[a,b],[c,d],[e,f]] Thanks – Indian Observer Sep 19 '19 at 04:06