lightswitch05 / table-to-json

Serializes HTML tables into JSON objects.
http://lightswitch05.github.io/table-to-json/
MIT License
756 stars 172 forks source link

displaying JSON-data not inline #26

Closed nikitalaletin closed 8 years ago

nikitalaletin commented 8 years ago

tableToJson.js works correctly and it was very useful for my project! but i want to display JSON-data in other way.

Now it works this way (inline):

[{"Title":"nikita","Sku":"245245245","Price ($)":"455"},{"Title":"anna","Sku":"2345","Price ($)":"678"}]

How I would like it to work:

[
    {
       "Title":"nikita",
       "Sku":"245245245",
       "Price ($)":"455"
    },{
       "Title":"anna",
       "Sku":"2345",
       "Price ($)":"678"
    }
]

how to change the code for correct output?

lightswitch05 commented 8 years ago

This has to do with converting the object to a string using JSON.stringify. To make it 'pretty print' you would call it like this:

var table = $('#example-table').tableToJSON();
var str = JSON.stringify(table, null, 2); // spacing level = 2
console.log(str);
alert(str);

example: http://plnkr.co/edit/MQUElyXxmUYfciHIiI7S?p=preview

nikitalaletin commented 8 years ago

Yes, it works correctly!