displaying JSON-data not inline
Closed this issue · 2 comments
nikitalaletin commented
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
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
Yes, it works correctly!