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

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

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 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!