{"id":13339457,"url":"https://github.com/tdast/tdast-util-to-json","last_synced_at":"2026-04-11T20:47:24.040Z","repository":{"id":144112470,"uuid":"294625843","full_name":"tdast/tdast-util-to-json","owner":"tdast","description":"tdast utility to serialize tdast to JSON (array)","archived":false,"fork":false,"pushed_at":"2020-09-13T08:51:41.000Z","size":7,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-09T17:18:06.763Z","etag":null,"topics":["array","ast","json","tabular-data","tdast","tdast-util","unist","util"],"latest_commit_sha":null,"homepage":"https://github.com/tdast","language":"JavaScript","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/tdast.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-11T07:31:35.000Z","updated_at":"2020-09-13T08:53:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"f85d230e-7dcc-4339-be6a-700549f742f9","html_url":"https://github.com/tdast/tdast-util-to-json","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/tdast/tdast-util-to-json","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdast%2Ftdast-util-to-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdast%2Ftdast-util-to-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdast%2Ftdast-util-to-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdast%2Ftdast-util-to-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tdast","download_url":"https://codeload.github.com/tdast/tdast-util-to-json/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdast%2Ftdast-util-to-json/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269804888,"owners_count":24477873,"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","status":"online","status_checked_at":"2025-08-10T02:00:08.965Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["array","ast","json","tabular-data","tdast","tdast-util","unist","util"],"created_at":"2024-07-29T19:20:03.536Z","updated_at":"2026-04-11T20:47:18.972Z","avatar_url":"https://github.com/tdast.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tdast-util-to-json\n\n[**tdast**][tdast] utility to serialize tdast to a JSON array string.\n\n---\n\n## Install\n\n```sh\nnpm install tdast-util-to-json\n```\n\n## Use\n\n```js\nimport toArray from 'tdast-util-to-array';\n\nconst tdast = {\n  type: 'table',\n  children: [\n    {\n      type: 'row',\n      index: 0,\n      children: [\n        {\n          type: 'column',\n          index: 0,\n          value: 'col1',\n        },\n        {\n          type: 'column',\n          index: 1,\n          value: 'col2',\n        },\n        {\n          type: 'column',\n          index: 2,\n          value: 'col3',\n        },\n      ],\n    },\n    {\n      type: 'row',\n      index: 1,\n      children: [\n        {\n          type: 'cell',\n          columnIndex: 0,\n          rowIndex: 1,\n          value: 'row1col1',\n        },\n        {\n          type: 'cell',\n          columnIndex: 1,\n          rowIndex: 1,\n          value: 'row1col2',\n        },\n        {\n          type: 'cell',\n          columnIndex: 2,\n          rowIndex: 1,\n          value: 'row1col3',\n        },\n      ],\n    },\n    {\n      type: 'row',\n      index: 2,\n      children: [\n        {\n          type: 'cell',\n          columnIndex: 0,\n          rowIndex: 2,\n          value: 'row2col1',\n        },\n        {\n          type: 'cell',\n          columnIndex: 1,\n          rowIndex: 2,\n          value: 'row2col2',\n        },\n        {\n          type: 'cell',\n          columnIndex: 2,\n          rowIndex: 2,\n          value: 'row2col3',\n        },\n      ],\n    },\n  ],\n};\n\nconsole.log(toJson(tdast));\n```\n\nyields\n\n```json\n[{\"col1\":\"row1col1\",\"col2\":\"row1col2\",\"col3\":\"row1col3\"},{\"col1\":\"row2col1\",\"col2\":\"row2col2\",\"col3\":\"row2col3\"}]\n```\n\n## API\n\n### `toJson(tdast[, options])`\n\n#### Interface\n```ts\nfunction toJson(\n  // tdast Table node\n  tdast: Table,\n  // options to configure serializer\n  options?: Options,\n): string;\n```\n\nSerializes a [tdast][] `Table` node into a JSON array string.\n\nIf columns and row cell cardinality do not match, an error will be thrown to inform that the JSON cannot be serialized.\n\nBy default, `toJson` will infer `Column` node values to use as keys.  If the tdast node does not contain `Column` nodes, or you wish to use explicit column keys, you can specify these with the `options.columns` property as detailed in the example below.\n\n#### Example\nUsing the same tdast tree in the earlier example,\n\n```js\nimport toJson from 'tdast-util-to-json';\n\nconst options = {\n  columns ['Col A', 'Col B', 'Col C'],\n  space: 4,\n};\n```\n\nyields\n\n```json\n[\n    {\n        \"Col A\": \"row1col1\",\n        \"Col B\": \"row1col2\",\n        \"Col C\": \"row1col3\"\n    },\n    {\n        \"Col A\": \"row2col1\",\n        \"Col B\": \"row2col2\",\n        \"Col C\": \"row2col3\"\n    }\n]\n```\n\n#### Related interfaces\n```ts\ninterface Options {\n  // array of column strings that will be used as object keys.  Overrides the column values detected in the tdast tree.\n  columns?: string[];\n  // JSON.stringify replacer function parameter\n  replacer?: (this: any, key: string, value: any) =\u003e any;\n  // JSON.stringify optional space parameter\n  space?: number | number;\n}\n```\n\n\u003c!-- Definitions --\u003e\n[tdast]: https://github.com/tdast/tdast\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftdast%2Ftdast-util-to-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftdast%2Ftdast-util-to-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftdast%2Ftdast-util-to-json/lists"}