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

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

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