JSON Parsing Error

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:

    • On PHP: use json_encode()
    • On Java Android: use org.json.JSONObject
    • A list of all other available library to play with JSON is listed in JSON official page.
  • To display and format JSON data, you can use JSONViewer.

I think the w3c parser is having issues, I couldn't even get it to parse this:

{
    "title" : "Followers Trend"
}

It gave me this error:

Validation errors:

lexer couldn't parse at "{
    "title" : "Followers Trend"
}"

http://json.bloople.net helps you visualise the code to find and correct errors.