How to filter and view the request response from just one of the columns in the json structure?

I have a request that returns a JSON structure with two columns. I’d like to separate and view only the left column, but I can’t find a way to do that.

I would very much like to do so, but so far all my efforts are without result. It would be incredibly helpful if that were possible.

Your JSON response is an array of objects.

The columns you are talking within the objects are key\value pairs.

As your response appears to be a flat array, to return just the keys you can use the JavaScript object.keys function.

const response = pm.response.json();

console.log(Object.keys(response));

Olá!! Obrigado pelo o apoio, mas essa essa função não funciona, já fiz algumas tentativas. É como se ele não encontrasse. Note que tem um número como label e outro numero como dado. Ex: “0.8866666666666667” : 0.11333333333333333. Estou em busca de algo que extraia somente o número como dado.

I don’t speak Portuguese, so I had to run that through a translator.

In your original post, you said you wanted the left most column, which would be the key.

Do you mean you want the values, not the keys?

For example, in the first object you want the 0.1133333333xxx value? (Not the 0.886666666xxx).

Do you want the value for the first object only, or do you want a list of all of the values?

Hello !! I do not speak English too. We draw… hehehe. I’m glad for your support. Achieving some advances, but now it’s time to turn the API response into a graph. Below is the response data. If you can help, thank you in advance.
{“diab_t1”:[[0.93,0.07]],
“diab_t2”:[[0.91,0.09]],
“cardio_stroke”:[[0.95,0.05]],
“cardio_dac”:[[0.92,0.08]],
“asthma”:[[0.87,0.13]],
“dpoc”:[[0.92,0.08]]}

Do you want a graph or a table?

If its a graph, what type of graph, and how should it look.

Your response seems to have a number of “conditions”. Diabetes, Stroke, Asthma, etc.

For each of those conditions. You have an array within an array. (Is that actually correct because that is going to complicate things).

Within the innermost array, there are two sets of numbers (readings?) for each condition. What do those numbers represent?

I could probably create a table, with the headings “Condition, Max Reading, Min Reading” or something similar.

If you actually want a graph, you will need to explain a bit more about how it should look.

This is a basic example of producing a table in the visualizer.

As your JSON is pretty flat, its not easy to target the elements, so I had to use {{@key}} and {{this}} to loop through the response.

If you want the readings split, then I would probably loop through the response first and create a new array with the name of the condition, and the two readings as that would then be easier to visualize. Rather than trying to write HTML code to deal with the formatting.

const response = pm.response.json();

var template = `

    <style type="text/css">
        .tftable {font-size:14px;color:#333333;width:100%;border-width: 1px;border-color: #87ceeb;border-collapse: collapse;}
        .tftable th {font-size:18px;background-color:#87ceeb;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;text-align:left;}
        .tftable tr {background-color:#ffffff;}
        .tftable td {font-size:14px;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;}
        .tftable tr:hover {background-color:#e0ffff;}
    </style>
    
    <table class="tftable" border="1">
        <tr>
            <th>Condition</th>
            <th>Readings</th>
        </tr>
        
        {{#each response}}
            <tr>
                <td>{{@key}}</td>
                <td>{{this}}</td>
            </tr>
        {{/each}}
    </table>

`;

pm.visualizer.set(template, {
    response: response
});

I did think about splitting the readings using the array indexes, and the following appears to work.

const response = pm.response.json().data

var template = `

    <style type="text/css">
        .tftable {font-size:14px;color:#333333;width:100%;border-width: 1px;border-color: #87ceeb;border-collapse: collapse;}
        .tftable th {font-size:18px;background-color:#87ceeb;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;text-align:left;}
        .tftable tr {background-color:#ffffff;}
        .tftable td {font-size:14px;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;}
        .tftable tr:hover {background-color:#e0ffff;}
    </style>
    
    <table class="tftable" border="1">
        <tr>
            <th>Condition</th>
            <th>High Reading</th>
            <th>Low Reading</th>
        </tr>
        
        {{#each response}}
            <tr>
                <td>{{@key}}</td>
                {{#each this}}
                    <td>{{[0]}}</td>
                    <td>{{[1]}}</td>
                {{/each}}
            </tr>
        {{/each}}
    </table>

`;

pm.visualizer.set(template, {
    response: response
});