A TypeScript/JavaScript library that converts JSON data into beautifully formatted tables with various styling options.
npm install json-to-table-format
# or
yarn add json-to-table-format
import { jsontoTable } from "json-to-table-format";
const data = [
{ name: "John", age: 30, city: "New York" },
{ name: "Alice", age: 25, city: "London" },
];
const result = jsontoTable(data);
console.log(result);
// Method 1: Using default export
const jsontoTable = require("json-to-table-format").default;
// Method 2: Using named export
const { jsontoTable } = require("json-to-table-format");
const data = [
{ name: "John", age: 30, city: "New York" },
{ name: "Alice", age: 25, city: "London" },
];
const result = jsontoTable(data);
console.log(result);
Output:
name age city
John 30 New York
Alice 25 London
import { jsontoTable } from "json-to-table-format";
const data = [
{ name: "John", age: 30, city: "New York" },
{ name: "Alice", age: 25, city: "London" },
];
const result = jsontoTable(data, "simple"); // or just jsontoTable(data)
console.log(result);
import { jsontoTable } from "json-to-table-format";
const data = [
{ name: "Alice", age: 25, city: "New York" },
{ name: "Bob", age: 30, city: "London" },
{ name: "Charlie", age: 35, city: "Paris" },
];
const result = jsontoTable(data, "ascii");
console.log(result);
Output:
+----------+--------+-------------+
|name age city |
+----------+--------+-------------+
|Alice 25 New York |
|Bob 30 London |
|Charlie 35 Paris |
+----------+--------+-------------+
Converts JSON data into a tabular string format.
-
data
(Array | Object): JSON data to convert. Can be an array of objects or a single object. -
style
(string, optional): Table style. Options:-
'simple'
(default): Clean table without borders -
'ascii'
: ASCII-style table with borders
-
-
string
: Formatted table as a string
// Single object
const singleData = { name: "John", age: 30, city: "New York" };
const result1 = jsontoTable(singleData);
// Array of objects
const arrayData = [
{ name: "John", age: 30, city: "New York" },
{ name: "Alice", age: 25, city: "London" },
];
const result2 = jsontoTable(arrayData, "ascii");
- ✅ Simple and clean API: Just one function call
- ✅ Multiple table styles: Simple and ASCII border styles
- ✅ Flexible input: Accepts single objects or arrays
- ✅ Automatic column sizing: Adjusts column widths based on content
- ✅ TypeScript support: Full TypeScript definitions included
- ✅ Cross-platform: Works in Node.js and browsers
Contributions are welcome! Please feel free to submit a Pull Request.
MIT