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

260
Vistas
How to convert string value to object in Javascript with command similar to eval in Python

In Python stringValue was given as a string variable:

stringValue = '{"DATA":{"VERSION":1.1, "STATE":True, "STATUS":"ONLINE"}}'

I can go ahead and "convert" or "cast" it as Python dictionary using eval built in function:

result = eval(stringValue)

Is there a way to do the same in javascript if we would be given var stringValue as:

var stringValue = '{"DATA":{"VERSION":1.1, "STATE":true, "STATUS":"ONLINE"}}'
about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

use eval

With one caveat ... you'll need to add ( and ) to the string

// this is the ORIGINAL value of the string in the question!!!
var stringValue = "{'DATA':{'VERSION':1.1, 'STATE':true, 'STATUS':'ONLINE'}}";
var result = eval(`(${stringValue})`);
console.log(result)

Now that code in the question was changed by you after I posted the original answer ... i.e. swapped ' and " - now you CAN use JSON.parse as a comment suggested

var stringValue = '{"DATA":{"VERSION":1.1, "STATE":true, "STATUS":"ONLINE"}}';
var result = JSON.parse(stringValue);
console.log(result);

about 4 years ago · Santiago Gelvez Denunciar
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