If you have been stuck with a JSON error and are not sure if your JSON is valid, use JSONLint.
JSONLint is a web-based tool for validating and reformatting JSON. Paste in some JSON and it’ll give you the syntax errors, if any. So let us say you give this tool the following input:
[{"ID":"1","Name":"Keith"}, {"ID":"2","Name":"Bill},
{"ID":"3","Name":"Govind"}, {"ID":"4","Name":"Kathy"}]
The tool returns an error message indicating unexpected TINVALID at line 9
What this error message means is that you have not enclosed your collection keys in quotes. On close observation, you can see the quotes on Bill (with ID 2) is not closed properly, hence causing the error. Specifying the quotes parses the JSON successfully. Also note that the tool neatly reformats the JSON output for us.
Pure JavaScript Version
There is a pure JavaScript version of the JSONLint service provided over here by Zach Carter, which makes it is easy to host this service on your own.
When I gave this tool the same input, the location of the error was much more easier to locate than I could do with the JSONLint service. Observe the arrow (circled) which pinpoints that the error is on the string Bill.
Bookmark this link for future use.
Tweet
2 comments:
Thanks for the utilities.
You can also use JSON.stringfy to reformat your object into the proper JSON format.
Usage:
JSON.stringify( obj )
Use this tool to validate your JSON: json validator
Post a Comment