Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
jQuery plugin that serializes HTML tables into JavaScript objects.
Table To JSON is a jQuery plugin that serializes HTML tables into JavaScript objects, returning an array of JSON objects keyed by column headings.
Table To JSON is an open-source jQuery plugin created by lightswitch05 that converts an HTML table element into an array of JavaScript objects. It takes a table selected via jQuery as input and outputs a JSON array where each object represents a row, with keys derived from the table's column headings. The plugin runs entirely in the browser, is distributed as a single JavaScript file, and is available on npm and jsDelivr CDN under the MIT license. A live demo and an editable Plunker template are linked from the repository.
th or td, and respects data-override attributes on heading cells.ignoreColumns option excludes specific column indexes, while onlyColumns includes only selected columns; onlyColumns takes precedence when both are supplied.ignoreHiddenRows (default true) skips hidden rows, and ignoreEmptyRows (default false) can skip rows with no text content.extractor option (aliased as textExtractor) accepts a function that processes each tbody cell, returning either text or an object with multiple fields; it can also be scoped per zero-based cell index.data-override attribute on any cell replaces its text content in the output, and textDataOverride lets you rename that attribute.allowHTML keeps HTML tags inside cells, and includeRowId adds the table row's id attribute to each output object with a configurable key name.Include the plugin script on your page, then call the plugin on a jQuery selection, for example $('#example-table').tableToJSON(). The plugin reads the table's first row for headings, iterates the tbody rows, applies the configured options, and returns an array of objects. Options are passed as a plain object to customize behavior; the README includes a worked example showing how ignoreColumns filters the output.
Yes, Table To JSON is open source and released under the MIT license, so it can be used freely in commercial and personal projects. The source code is hosted on GitHub and the package is published to npm.
Yes, the plugin supports tables with merged cells. Rowspan and colspan support was contributed by Mottie, and a subsequent bug involving rowspan/colspan with other options was fixed by danielapsmaior. This makes it suitable for complex HTML tables.
Use the ignoreColumns option with an array of zero-based column indexes, for example ignoreColumns: [0] to skip the first column. Alternatively, onlyColumns lets you specify which columns to keep and takes precedence over ignoreColumns when both are provided.
