# add Html Table rows data into JSON array Object (ok)

## [add Html Table rows data into JSON array Object](https://stackoverflow.com/questions/44097281/add-html-table-rows-data-into-json-array-object)

[Ask Question](https://stackoverflow.com/questions/ask)Asked 4 years, 2 months agoActive [2 years, 8 months ago](https://stackoverflow.com/questions/44097281/add-html-table-rows-data-into-json-array-object?lastactivity)Viewed 3k timesReport this ad11

I am new in MVC. I want to add my HTML Table data into JSON array object. and that object I want to pass to Action Using ajax post.

I am not able to convert my html rows to json object. Can Anybody have solution for the same It will be appreciable

thanks In advance[arrays](https://stackoverflow.com/questions/tagged/arrays)[json](https://stackoverflow.com/questions/tagged/json)[html-table](https://stackoverflow.com/questions/tagged/html-table)[asp.net-mvc-5](https://stackoverflow.com/questions/tagged/asp.net-mvc-5)[Share](https://stackoverflow.com/q/44097281)[Improve this question](https://stackoverflow.com/posts/44097281/edit)Followasked May 21 '17 at 13:11[![](https://www.gravatar.com/avatar/b5dec7b28893c0bcee0f4b3332bda86e?s=64\&d=identicon\&r=PG\&f=1)](https://stackoverflow.com/users/5702986/vsagar)[Vsagar](https://stackoverflow.com/users/5702986/vsagar)17711 silver badge1414 bronze badges[Add a comment](https://stackoverflow.com/questions/44097281/add-html-table-rows-data-into-json-array-object)

### 1 Answer

[Active](https://stackoverflow.com/questions/44097281/add-html-table-rows-data-into-json-array-object?answertab=active#tab-top)[Oldest](https://stackoverflow.com/questions/44097281/add-html-table-rows-data-into-json-array-object?answertab=oldest#tab-top)[Votes](https://stackoverflow.com/questions/44097281/add-html-table-rows-data-into-json-array-object?answertab=votes#tab-top)4

HTML

```
     <table id="table">
      <tr>
        <td>Alfreds Futterkiste</td>
        <td>Maria Anders</td>
        <td>Germany</td>
      </tr>
      <tr>
        <td>Centro comercial Moctezuma</td>
        <td>Francisco Chang</td>
        <td>Mexico</td>
      </tr>
      <tr>
        <td>Ernst Handel</td>
        <td>Roland Mendel</td>
        <td>Austria</td>
      </tr>
      <tr>
        <td>Island Trading</td>
        <td>Helen Bennett</td>
        <td>UK</td>
      </tr>
      <tr>
        <td>Laughing Bacchus Winecellars</td>
        <td>Yoshi Tannamuri</td>
        <td>Canada</td>
      </tr>
      <tr>
        <td>Magazzini Alimentari Riuniti</td>
        <td>Giovanni Rovelli</td>
        <td>Italy</td>
      </tr>
    </table>
```

JS code to create JSON Array

```
  var table = document.getElementById('table');
  var jsonArr = [];
  for(var i =0,row;row = table.rows[i];i++){
       var col = row.cells;
       var jsonObj = {
           company : col[0].innerHTML,
           contact : col[1].innerHTML,
           country : col[2].innerHTML
         }

      jsonArr.push(jsonObj);
  }


  console.log(jsonArr);
```

<https://jsfiddle.net/0h957km9/3/>
