Is my JSON Valid?

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

Valid JSON Tool

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.

Valid JSON Tool

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.

Valid JSON Tool

Bookmark this link for future use.






About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal.

2 comments:

Larry Battle said...

Thanks for the utilities.
You can also use JSON.stringfy to reformat your object into the proper JSON format.
Usage:
JSON.stringify( obj )

Unknown said...

Use this tool to validate your JSON: json validator