2

I need to parse a JavaScript file that exists on the Web with Node.

The file looks as follows:

var obj = {"data": [{"property1":40}]}

Is there any way I can download the file as a string, and parse it so it to an object? i.e. so that after I have parsed the file I can do:

var data = obj.data;
1
  • Sure, you can use a http module to download and parse the string with eval(). But remember, eval is evil. Commented Oct 30, 2020 at 11:50

1 Answer 1

2

You can use eval for it, but be careful - you can also execute unwanted code

const fileContent = 'var obj = {"data": [{"property1":40}]}';
eval(fileContent);
var data = obj.data;
console.log(data);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.