Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

287
Visualizações
How to fetch and save multiple values as different variables in environment for postman?
{
    "Test1": {
        "label1": "Testing",
        "duration": [
            {
                "Value": "987654",
                "Ans": "True"
            },
            {
                "Value": "987159",
                "Ans": "True"
            }
        ]
    }
}

I want to fetch the value of "Value" and save them with different name in environment. Ex: "987654" saved as result1 and "987159" saved as result2 in environment.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to loop through the array of the response body and get it to save each desired item as as unique variable. Based on your requiremments it would be:

var jsonData = pm.response.json();
for (let i = 0; i < jsonData.Test1.duration.length; i++) {
    pm.environment.set(
        "result" + [i+1], jsonData.Test1.duration[i].Value
    )
}

The first block in an array is actually an object value of 0, hence in the function above the loop has to stat with i = 0, however as you wanted the variable to start with integer '1' for the first value required, the name is set as "result" + [i+1] to ensure they are saved with result(n), starting with 'result1' onwards

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda