{"id":21327011,"url":"https://github.com/coderosh/jsonfromtable","last_synced_at":"2025-07-12T07:31:06.653Z","repository":{"id":57285725,"uuid":"378432387","full_name":"coderosh/jsonfromtable","owner":"coderosh","description":"Convert html tables to object (or array). Supports complex rowspan and colspan.","archived":false,"fork":false,"pushed_at":"2022-01-24T04:36:11.000Z","size":472,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-11T22:14:48.874Z","etag":null,"topics":["json-from-table","table-to-json"],"latest_commit_sha":null,"homepage":"https://coderosh.github.io/jsonfromtable/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coderosh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-19T14:32:04.000Z","updated_at":"2024-10-20T12:32:30.000Z","dependencies_parsed_at":"2022-09-20T00:06:38.219Z","dependency_job_id":null,"html_url":"https://github.com/coderosh/jsonfromtable","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderosh%2Fjsonfromtable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderosh%2Fjsonfromtable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderosh%2Fjsonfromtable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderosh%2Fjsonfromtable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coderosh","download_url":"https://codeload.github.com/coderosh/jsonfromtable/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225802618,"owners_count":17526452,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["json-from-table","table-to-json"],"created_at":"2024-11-21T21:12:49.857Z","updated_at":"2024-11-21T21:12:50.492Z","avatar_url":"https://github.com/coderosh.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"./images/banner.png\" alt=\"banner\" width=\"100%\"\u003e\n\n\u003cp align=\"center\"\u003e\n  Convert html tables to object (or array). Supports complex rowspan and colspan.\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.npmjs.com/package/jsonfromtable\"\u003e\u003cimg alt=\"NPM\" src=\"https://img.shields.io/npm/v/jsonfromtable\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/coderosh/jsonfromtable\"\u003e\u003cimg alt=\"MIT\" src=\"https://img.shields.io/badge/license-MIT-blue.svg\" /\u003e\u003c/a\u003e\n  \u003ca href=\"#\"\u003e\u003cimg alt=\"CI\" src=\"https://img.shields.io/github/workflow/status/coderosh/jsonfromtable/CI\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/coderosh/jsonfromtalbe\"\u003e\u003cimg src=\"https://img.shields.io/badge/PRs-welcome-brightgreen.svg\" alt=\"PRs welcome!\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/coderosh/jsonfromtalbe\"\u003e\u003cimg src=\"https://img.shields.io/badge/types-typescript-blue.svg\" alt=\"Typescript\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Installation\n\nInstall via npm\n\n```sh\nnpm install jsonfromtable\n```\n\nOr via yarn\n\n```sh\nyarn add jsonfromtable\n```\n\n## Usage\n\n### From html string\n\n- Get array of objects with title as keys\n\n  ```js\n  const { JSONFromTable } = require('jsonfromtable')\n\n  const obj = JSONFromTable.fromString(`\u003chtml\u003e...\u003c/html\u003e`)\n  console.log(obj)\n  /*\n  [\n    {\n      title: value1,\n      title2: value2,\n      ...\n    },\n    ...\n  ]\n  */\n  ```\n\n- Get array of title and body\n\n  ```js\n  const { JSONFromTable } = require('jsonfromtable')\n\n  const { headers, body } = JSONFromTable.arrayFromString(`\u003chtml\u003e...\u003c/html\u003e`)\n  console.log(headers) // [title1, title2, title3, ...]\n  console.log(body) // [ [val1, val2, ...], [val3, val4, ...], ... ]\n  ```\n\n### From url\n\n```js\nconst { JSONFromTable } = require('jsonfromtable')\n\nasync function main() {\n  const obj = await JSONFromTable.fromUrl(`https://...`)\n  console.log(obj)\n\n  const { headers, body } = await JSONFromTable.arrayFromUrl(`https://...`)\n  console.log(headers)\n  console.log(body)\n}\n\nmain()\n```\n\n\u003cbr /\u003e\n\nEach function in `JSONFromTable` accepts two arguments. First is source (html string or url) and second is `options`.\n\n```ts\ninterface Options {\n  titles?: string[] // custom titles (eg: [\"sn\", \"name\", \"title\"])\n  firstRowIsHeading?: boolean // use first row for titles ?\n  includeFirstRowInBody?: boolean // add first row in body ?\n  tableSelector?: string // css selector for table (eg: table.wikitable)\n  rowColSelector?: [string, string] // css selectors for row and col (eg: [\"tr\", \"th,td\"])\n  shouldBeText?: boolean // if false value is html else true\n  trim?: boolean // should trim the value ?\n}\n```\n\n## Example\n\n```js\nconst str = `\u003ctable\u003e\n  \u003ctr\u003e\n    \u003cth\u003ename\u003c/th\u003e\n    \u003cth\u003ealias\u003c/th\u003e\n    \u003cth\u003eclass\u003c/th\u003e\n    \u003cth\u003einfo\u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd colspan=\"2\"\u003eRoshan\u003c/td\u003e\n    \u003ctd\u003eEng\u003c/td\u003e\n    \u003ctd rowspan=\"2\"\u003ena\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd rowspan=\"2\"\u003eJohn\u003c/td\u003e\n    \u003ctd colspan=\"2\"\u003eCook\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd rowspan=\"2\"\u003eDanger\u003c/td\u003e\n    \u003ctd colspan=\"2\"\u003e Ninja\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eAGuy\u003c/td\u003e\n    \u003ctd\u003eEng\u003c/td\u003e\n    \u003ctd rowspan=\"2\"\u003eEats a lot \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd colspan=\"2\"\u003e Dante\u003c/td\u003e\n    \u003ctd rowspan=\"2\"\u003eArt\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eJake\u003c/td\u003e\n    \u003ctd\u003eake\u003c/td\u003e\n    \u003ctd\u003eActor\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e`\n\nconst obj = JSONFromTable.fromString(str, {\n  tableSelector: 'table',\n  trim: true,\n})\n\nconsole.log(obj)\n```\n\n\u003cimg src=\"./images/example.png\" /\u003e\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderosh%2Fjsonfromtable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoderosh%2Fjsonfromtable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderosh%2Fjsonfromtable/lists"}