0

I want to format the following data from String to "set of data" to match the series in HighCharts.

I've tried parsing it with JSON.parse but, of course, this is not a JSON, so it won't work.

So I have the following string:

var str = "[
{name: 'Abril', data: [107, null, 635, 203, 2]}, 
{name: 'Mayo', data: [133, 156, 947, 408, 6]}, 
{name: 'Junio', data: [1052, null, 4250, 740, 38]}
]"

The desired result is:

var data = [
{name: 'Abril', data: [107, null, 635, 203, 2]}, 
{name: 'Mayo', data: [133, 156, 947, 408, 6]}, 
{name: 'Junio', data: [1052, null, 4250, 740, 38]}
]

Replacing the quotes with nothing won't work either.

1 Answer 1

1

I managed to do it with

var data = eval(str);
Sign up to request clarification or add additional context in comments.

2 Comments

Better is using JSON.parse();
That was exactly the problem, JSON.parse() wouldn't work.

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.