ariefbayu ariefbayu - 7 days ago 5
JSON Question

JSON Parsing Error

I got problem. I have this JSON automatically generated by Open Flash Chart php library. The problem is, OFC report

JSON Parse Error [Syntax Error]
while test result using http://www.jsonlint.com/ report that my JSON is fine. But, w3c parser report error too:(

Any help?

Here's the JSON:

{
"title": "Followers Trend",
"elements": [
{
"type": "area_hollow",
"fill-alpha": 0.35,
"values": [

],
"colour": "#5B56B6",
"text": "Followers",
"font-size": 12
}
],
"x_axis": {
"colour": "#A2ACBA",
"grid-colour": "#D7E4A3",
"offset": false,
"steps": 4,
"labels": {
"steps": 2,
"rotate": "vertical",
"colour": "#A2ACBA",
"labels": [

]
}
},
"x_legend": {
"text": "Week Trend (2009-08-17 - 2009-08-24)",
"style": "{font-size: 20px; color: #778877}"
},
"y_axis": {
"min": 0,
"max": 150,
"steps": 30
}
}

Answer

A few things I learned while playing with JSON is:

  • If you have validate the JSON on various JSON validation services and the result is GOOD. But, when you failed to eval it, try to wrap your JSON using ( and ) => ({jsondata})

    var json = eval( "(" + jsonString + ")" );
    
  • NEVER build the JSON yourself. It's a gate to failure. Always use official or popular JSON library (depending on your language). For example:

  • To display and format JSON data, you can use JSONViewer.