jsontotables
Easily convert JSON data to Markdown tables, plaintext tables, TSV, or HTML for documentation, reports, Notion, GitHub, Google Docs, and React UIs.
✨ Features
- 🔄 Convert JSON to Markdown, TSV, plaintext, or HTML table formats
- ⚙️ Command-line interface (CLI) and TypeScript library
- ⚛️ React utility (
jsonToReactTable
) available - 🔍 Smart sorting, column selection, and text alignment
- 📦 Lightweight, dependency-free, fully typed
📦 Installation
As a Library (Local)
npm install jsontotables
As a CLI Tool (Global)
npm install -g jsontotables
📚 Usage Examples
1. Library: Convert JSON to Markdown Table
import { jsontotables } from 'jsontotables'
const json = [
{ name: 'Alice', age: 25 },
{ name: 'Bob', age: 30 }
]
// Convert JSON to Markdown format and store as a string
const markdownTable = jsontotables(json, { format: 'markdown' })
// Output the result
console.log(markdownTable)
// Save to file (Node.js)
import { writeFileSync } from 'fs'
writeFileSync('output.md', markdownTable)
2. Library: Convert to HTML or TSV
jsontotables(json, { format: 'html' })
jsontotables(json, { format: 'tsv' })
3. React Component Usage
import { jsonToReactTable } from 'jsontotables/react'
const table = jsonToReactTable(data, {
tableClassName: 'my-table',
thClassName: 'header',
tdClassName: 'cell',
align: { age: 'right' }
})
4. CLI Examples
# Convert JSON to Markdown and print to console
jsontotables data.json
# Convert to TSV and save to file
jsontotables data.json --format tsv --out table.tsv
# Convert to plaintext and write to output
jsontotables data.json --format plaintext --out output.txt
Or without installing:
npx jsontotables data.json --format tsv
⚙️ CLI Options
Option | Description |
---|---|
--format |
Output format: markdown, plaintext, tsv, html |
--only |
Comma-separated list of columns to include |
--sortBy |
Column to sort rows by |
--className |
HTML table class name (HTML only) |
--help |
Show usage |
📤 Output Examples
Markdown
| name | age |
|:------|----:|
| Alice | 25 |
| Bob | 30 |
TSV
name age
Alice 25
Bob 30
Plaintext
name age
----- ---
Alice 25
Bob 30
📁 Project Structure
src/jsontotables.ts
– JSON to text/markdown/html/tsvsrc/react/
– React rendering logicsrc/bin/cli.ts
– CLI entry pointsrc/exportToTsv.ts
– TSV formattersrc/helpHandlers.ts
– CLI help/usage text
📄 License
MIT © anthonyhalim150
🤝 Contributing
Contributions, ideas, bug reports, and feature requests are welcome!
If you'd like to help:
- ⭐ Star the repo to show support
- 🐛 Open an issue for bugs or suggestions
- 🔧 Fork the project and submit a pull request
- 📃 Ensure your code is linted and tested with
vitest
Let’s make jsontotables
better for the whole developer community!