Javascript: JSON validator

JSON is fine and dandy when it works well, but damned if it's missing a comma or the bloody keywords are quoted in the wrong characters.

I had a problem with some (assumingly) well formed JSON, but it kept puzzled me for hours when a jQuery AJAX post kept silently failing.

Eventually I stumbled upon jsonlint.com, a nifty site that simply validates your JSON and formats it for easy reading.

My example JSON:

{
    'num_votes': 5,
    'up': 4,
    'down': -1
}

Can you spot what's wrong with it?

No? Neither could I... until I got fed up and changed the single quotes with double quotes for the hell of it.

AND IT BLOODY WORKED!

This is the now valid JSON:

{
    "num_votes": 5,
    "up": 4,
    "down": -1
}

FML.

8891
Oh well, back to it!

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog