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

166
Vistas
Is there a way to convert a literal object in a string to an object?

If I have this string:

{some_name:{other_name:"text",array:["first","second",3]}}

Is there a way to turn it into a usable object in JavaScript?

JSON.parse() can't do it because it expects the attributes to be surrounded in quotes like this

{"some_name":{"other_name":"text","array":["first","second"]}}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Quick and dirty

eval('foo = {some_name:{other_name:"text",array:["first","second",3]}}');

console.log(foo);

foo will be the usable object.

(but don't do it, eval is evil)


Cleaner way

You can transform it to a valid JSON and parse it.

const bar = '{some_name:{other_name:"text",array:["first","second",3]}}';
const foo = JSON.parse(bar.replace(/([^"])(\w+):/g, '$1"$2":'))

console.log(foo);

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