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

189
Visualizações
Build array dynamically with JavaScript/Postman

Looking to create a JSON response body with JavaScript/Postman as a pre-request script with some dynamic variables. The issue I'm having is dynamically generating arrays inside the array. The data I'm receving is a CSV file so the value is like so Value1|Value2 and I need to separate the values from the pipe separator and pushing them into their own category array

Using the CSV value from the above example the output should be like this:

{
"id": 1,
"store": 1,
"title": custom_title,
"url": custom_url,
"content": content,
"categories":[
    {
       "id":1,
       "name":"Value1",
       "type":"Type"
     },
     {
       "id":1,
       "name":"Value2",
       "type":"Type"
     },
    //add more if needed dynamically
]
}

I tried something like this

var catNum = "Blog|Healthy".split('|');
catNum.forEach((value, name) => bodyRequest.categories.push({ 
    "id": 1,
    "type": "Category",
    "name": value.toLowerCase(),
    "blog_category_path": value
}));

Trying to push the above into the categories array "categories":[]

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

0

var catNum = "Blog|Healthy".split('|');

returns an array strings to catNum.

Do this rather

catNum.forEach(value => bodyRequest.categories.push({ 
    "id": 1,
    "type": "Category",
    "name": value.toLowerCase(),
    "blog_category_path": value
}));
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