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.

Will you give this article a +1 ? Thanks in advance

About The Author

Suprotim Agarwal
Suprotim Agarwal, ASP.NET Architecture MVP (Microsoft Most Valuable Professional) works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He is the Editor of a Developer Magazine called DNC Magazine. He has also written two EBooks 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook

Follow him on twitter @suprotimagarwal

1 comment:

Larry Battle said...

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