David Sonnenfeld David Sonnenfeld - 1 month ago 5x
HTML Question

html table to json - modify cells

Well, I have following html table:

<table id="people" border="1">
<td>New York</td>
<p>New York</p>
<td>New York</td>

Now when I use the jquery tableToJson function I get this output:

{"Name":"Oscar","Places":"New York","Grade":"16.5"},
{"Name":"Antonio","Places":"New York\n\t\t\tChicago\n\t\t\t\tToronto","Grade":"14"},
{"Name":"Jessica","Places":"New York","Grade":"19"}

Now look at Antonio, the function created

{"Name":"Antonio","Places":"New York\n\t\tChicago\n\t\t\t\tToronto","Grade":"14"}

But instead of


I want places also to be displayed as a JSON array like this:

{"Name":"Antonio","Places":["New York","Chicago","Toronto"],"Grade":"14"}

I know there are options described here (https://github.com/lightswitch05/table-to-json), but I don't know which one to use, or how to use them, as it is not really documented, how to use them in detail.

Any help would be really appreciated :-)


If you want to update the existing array try using this

var places = [
    {"Name":"Oscar","Places":"New York","Grade":"16.5"},
    {"Name":"Antonio","Places":"New York\n Chicago\n Toronto","Grade":"14"},
    {"Name":"Jessica","Places":"New York","Grade":"19"}

for(var x=0;x<places.length;x++){
  places[x].Places = places[x].Places.split("\n");