Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

82
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda