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

73
Visualizações
Add nested object properties to the main object

I have a response from an api call which is an array of Objects. I want to modify every object by removing the nested object 'company' and nested it directly to the main object. Is there a way to do that with a fast way ?

{
    "ip": "127.0.0.1",
    "hostname": "test.compute.amazonaws.com",
    "city": "São Paulo",
    "region": "São Paulo",
    "country": "Brazil",
    "loc": "-33.5375,-36.31",
    "org": "AS16509 Amazon.com, Inc.",
    "postal": "01000-000",
    "timezone": "America/Sao_Paulo",
    "company": {
      "name": "Amazon Data Services Brazil",
      "domain": "amazon.com",
      "type": "hosting"
    },
    "countryCode": "BR"
}

I want to change the json to this

{
    "ip": "127.0.0.1",
    "hostname": "test.compute.amazonaws.com",
    "city": "São Paulo",
    "region": "São Paulo",
    "country": "Brazil",
    "loc": "-33.5375,-36.31",
    "org": "AS16509 Amazon.com, Inc.",
    "postal": "01000-000",
    "timezone": "America/Sao_Paulo",
    "name": "Amazon Data Services Brazil",
    "domain": "amazon.com",
    "type": "hosting"
    "countryCode": "BR"
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I have used this function but I am checking if there's a faster method.

const formatObj = (obj) =>{
  obj.name = obj.company.name;
  obj.domain = obj.company.domain;
  obj.type = obj.company.type;
  delete obj.company
  return obj
}
about 4 years ago · Juan Pablo Isaza Relatório

0

var newList = listFromAPI.map((object) => {
delete object.company
return {...object};
});

here newList will have all the list of objects without company property

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