1

I have an array of JSON plots which I store in MySQL. When I retrieve this information from MySQL it is given as one long string. How can I restore this back into an array of JSON objects using Javascript? I'm running this using NodeJS and MySQL package.

My data is returned like the following:

'[{"x":0,"y":0},{"x":1,y:1},{"x":2,"y":2}]'

What I would like to be able to do is use the data like:

var data = [{"x":0,"y":0},{"x":1,"y":1},{"x":2,"y":2}];
console.log(data[0].x);

I've had a try using JSON.parse and originally stored the data using JSON.stringify on the array, but it is not behaving as I would expect.

Are there any methods or packages available to handle this?

Edit: I realize now that this is not JSON but rather objects. Apologies for the wrong terminology here, but my problem still remains.

2
  • 4
    That isn't JSON. Commented Sep 4, 2017 at 20:36
  • In JSON, quotes must be double quotes, and all property names must be strings (e.g., in quotes), so this is not json. Commented Sep 4, 2017 at 20:37

1 Answer 1

1

var data = new Function ('return ' + dataString)();

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.