Hi all,
I am C++ programmer - trying to get to grips with Postman, JSON, REST APIs etc.
I am trying to write a Postman test to visualize some JSON response data - which I would like to show in a table format with the key names as column headings.
The problem is that the number of data items in a response can vary and the key names can also vary - depending on the input parameters.
Details (like screenshots):
So say, for the following JSON which has two data items:
{
"data": [
{
"input": [
{
"value": "ABC",
"identifierType": "a1"
}
],
"output": [
{
"value": "BT",
"identifierType": "b1",
"name": "BT GROUP",
"status": "Active",
"classification": "Ordinary"
}
]
},
{
"input": [
{
"value": "BCD",
"identifierType": "a1"
}
],
"output": [
{
"value": "EFG",
"identifierType": "b1",
"name": "SIEMENS",
"status": "Active",
"classification": "Ordinary"
}
]
}
]
}
I can get the values such as ABC, EFG, a1,b1, Ordinary etc - but I want to get the names such as ‘input->value’, ‘input->identifierType’,‘output->value’, ‘output->identifierType’, ‘output->status’
I am using something like the following to get the values in my parseData method
const results = response.map(elem => (
{
inputValue: elem.input[0].value,
inputIDType: elem.input[0].identifierType,
ouputValue: elem.output[0].value,
outputIDType: elem.output[0].identifierType,
outputName: elem.output[0].name
}
));
which is fine, but I can’t figure out how to do something similar for the key names.
Just to be clear, in any single request and JSON response, all the input and output key names will be the same for all the entries. If I make a different request with different input parameters, then it is possible that the key names in that response will be different.
thanks in advance for any tips/help.