Hey there, it's PostMan 6.0.10! I've been diving into test scripts and could use some help in understanding how to query and examine JSON responses more effectively. Even after going through the excellent documentation, I still have a bit of confusion.
In particular, let's take a look at this JavaScript snippet:
pm.test("Verify the contents of the response payload are correct", function () {
// ???
});
I am looking to:
- Identify if the response is a single JSON object or an array of objects
- If it's an array, determine its size (number of elements)
- If it's a single object, extract specific fields (let's say a field named "
fizzbuzz
") along with their values and data types (string, number, bool, null)
Scenario #1: JSON response is an array
For example:
[
{
"fizz": "buzz",
"foo": 53
},
{
"fizz": "bozz",
"foo": 291
}
]
Scenario #2: JSON response is a single object
Like this:
{
"fizz": "buzz",
"foo": 293
}
Do you have any suggestions on how to go about inspecting these JSON response payloads?