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

176
Visualizações
How can I read json data which has its tag/identifier in quotes?

I'm using NodeJS to fetch the NPM registry with the code below.

import fetch from "node-fetch";

let url = "https://registry.npmjs.com/[package-name]";

let settings = { method: "Get" };

fetch(url, settings)
    .then(res => res.json())
    .then((json) => {
    console.log(json.versions)
    });

So, the response that I get in my result is:

{
  _id: '123456789',
  name: 'package-name',
  'dist-tags': { latest: '2.0.0' },
  versions: {
    '2.0.0': '...'
}
...
}

I am trying to read the 'versions' section, but the issue I have is that the version number 2.0.0 is encased in quotes and it might change but I want to find that value. How can I read it?

Thanks in advance, and let me know any other info I missed.

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

0

You'll have to check if the versions has the key you want.

if(Object.keys(response.versions).includes('2.0.0')){
  // response.versions['2.0.0'] exists
}

Or you could iterate through Object.keys(response.versions) and handle each version entry as you wish.

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