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

319
Vistas
Converting a string to an *almost* JSON

So I have a string that looks like this:

'{utopia:1,word:2,sentence:3,tourism:4,home:5}'

I'd like to convert it to an object that looks like:

{utopia:1,word:2,sentence:3,tourism:4,home:5}

I tried using JSON.parse() on the original string but got 'SyntaxError: Unexpected token u in JSON at position 1'. I think this is because the keys of the object don't have quotations around them (in a classic JSON object, it would be like "utopia":1,...)

Not sure how to fix this. Any suggestions are much appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I think you can first replace { and } in string with empty strin then yourstring.split(',') After that [items].reduce((a, v) => ({ ...a, [v]: v}), {}) to build your object

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