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

84
Views
Read json literals or json objects from arbitrary javascript files

I want to read a set of variables that happen to be valid json objects from js files. The problem is, I don't know what the js file looks like(it is uploaded by users) and I only care about the variables I need.

For example, I got this file:

// xxx_file.js
const a = {"foo":"bar", "urls":["url1", "url2", "url2"]};
const b = {"username":"silk", "age":18};
// some functions or other variables

Now I need to read variable a and b from it, should I just use eval() or there're other ways to do it more easily?

Those variables are not necessarily const, but I only need the value when they are declared, whether they are modified or not after initialization is not my concern.

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