Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

321
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!