I am trying to implement a line chart using highcharts, in which I want to color specific points.
So I am using following statement.
JSON.parse("[{x: 1,y: 0},{x:2,y:5,marker:{fillColor:'red'}},{x:3,y:8}]");
to color the point (2,5) as red.
But, it is showing error as SyntaxError: JSON.parse: expected property name or '}'
Valid JSON strings require the property names to be quoted.
This can be corrected by quoting the property names like below:
JSON.parse('[{"x": 1, "y": 0}, {"x":2, "y":5, "marker": {"fillColor":"red"}}, {"x":3, "y":8}]');
As it was said earlier JSON object names must to be quoted. So JSON.parse will parse only that string, valid JSON.
But if you can't for any reason change format of your string you can also parse it using eval
function which can accept your syntax. But be careful! That's pretty good way for exploit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With