Q:

Convert Form data to JSON

<html>
  <head></head>
  <body>
      <form name="abc" action="#" method="post">
        
        Name: <input type="text" name="name"><br>
        Age : <input type="text" age="name"><br>
        <input type="submit"><br>
        </form>
    
        </body>
</html>

Can any one write this HTML code in such a way that when I will submit this form the the form data will be submitted in JSON format . 

A:

A pure JavaScript solution would be:
var form = document.getElementsByTagName('form')[0];

form.addEventListener('submit',function(event){
     event.preventDefault();
     var data = {
         "name":this.name.value,
         "age":this.age.value
     };

     console.log(data);
});

