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

86
Visualizações
Read json literals or json objects from arbitrary javascript files

I want to read a set of variables that happen to be valid json objects from js files. The problem is, I don't know what the js file looks like(it is uploaded by users) and I only care about the variables I need.

For example, I got this file:

// xxx_file.js
const a = {"foo":"bar", "urls":["url1", "url2", "url2"]};
const b = {"username":"silk", "age":18};
// some functions or other variables

Now I need to read variable a and b from it, should I just use eval() or there're other ways to do it more easily?

Those variables are not necessarily const, but I only need the value when they are declared, whether they are modified or not after initialization is not my concern.

about 4 years ago · Juan Pablo Isaza
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