w3resource
JSON Tutorial

Validate JSON with JSONLint

Description

In this page you will see how you can validate your JSON data using JSONLint.

What is JSONLint

JSONLint is an open source project which allows you to validate your JSON data. Since when you are working with any programming language and JSON, if your JSON data is not properly formatted, it can cause error, it is better to validate your JSON data beforehand.

You can check your JSON data by simply copying it to the JSONLint online (http://jsonlint.com/).

JSONLint - the JSON validator

Example of validating JSON with JSONLint

We will take a simple piece of code and with the help of JSONLint, we will validate that. Here is the code

 {
  "firstName": "Bidhan",
  "lastName": "Chatterjee",
         	  age: 40,
  "email":[email protected]
         	  } 

Upon copying this code in the JSONLint and pressing Validate button, it shows the following error :

JSONLint - showing validation error

So you can see that it shows you the line number and the kind of error occurred.

Here, it says that it says that 'age' must be written as a string on line number 3. So, we enclose age as "age" directly in the JSONLint and press validate button again.

Here is the output :

JSONLint - showing validation error 2

Now it says that the error is on line 5. It should be "[email protected]" instead of [email protected] And after making that change it validates the JSON.

..

JSONLint - validatd JSON

Many of our valued users post comments along with piece of code. Disqus may, false positively, consider those piece of code as Bad or Starnge syntax and send those comments to spam automatically. Even if that happens, we will make sure those useful comments are taken out of spam and approved. It may take a couple of days for that though, but any useful comment will be brought to public view for sure. We regret if that happend to any user. You may write us directly regarding this to - w3resource[at]yahoo[dot]com.