2.0.3 • Published 3 years ago

jsonify-my-table v2.0.3

Weekly downloads
3
License
BSD-3-Clause
Repository
github
Last release
3 years ago

jsonify-my-table

Convert a HTML table to JSON. Actually, to an array of JSON objects.

TL;DR

const { res } = document
  .getElementById('tableID')
  .jsonify();

Usage

Consider a HTML table with id=myTable.

<table id="myTable">
  ...
</table>

To convert it to an array of JSON objects:

const table = document.getElementById('myTable');
const obj = table.jsonify();
const result = obj.res; // Array of objects.

jsonify only works on table (HTMLTableElement).

Data members

In the above example, obj contains following data members:

  • error a flag which indicates if an error was occurred. It is false if no errors occurred, else contains the error message.
  • res the array containing JSON objects.
  • headers the keys in the objects (also, the table headers).
const table = document.getElementById('tableID');
const obj = table.jsonify();

if (!obj.error) {
  // obj.res...
}

Errors

  1. There are no rows in the table.
  2. Headers repeat.
  3. <td> has more than one child nodes.

Note

Use this for the client-side JavaScript. Though this module is published as a Node Package Module, it can not run on server-side JavaScript. This is because it makes use of document, which is not available in Node, as is.

To add it in the <script> tag, make use of Unpkg.

Example: <script src="unpkg.com/jsonify-my-table@latest/jsonify-my-table.min.js"></script>

2.0.3

3 years ago

2.0.2

4 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago