Skip to content
/ json-table Public

Set of tools for converting JSON data into tables (HTML, XLSX, ASCII).

License

Notifications You must be signed in to change notification settings

x0k/json-table

Repository files navigation

JSON Table

Set of tools for converting JSON data into tables (HTML, XLSX, ASCII).

Install

npm install @json-table/core

Usage

import { makeBlockFactory } from "@json-table/core/json-to-table";
import { blockToASCII } from "@json-table/core/block-to-ascii";

const block = makeBlockFactory({
  cornerCellValue: "№",
  joinPrimitiveArrayValues: true,
});
const asciiTable = blockToASCII(block(data));

Input data:

{
  "key": "val",
  "primitiveArr": [1, "two", false],
  "object": {
    "key1": "value1",
    "key2": 789,
    "key3": {
      "nestedKey": "nestedVal"
    }
  },
  "nestedArray": [
    {
      "name": "John",
      "age": 30,
      "isStud": false
    },
    {
      "name": "Alice",
      "age": 25,
      "isStud": true
    }
  ]
}

Output:

+-----+---------------+---------------------------+--------------------------+
| key | primitiveArr  |          object           |         nestedArray      |
+-----+---------------+--------+------+-----------+---+-------+-----+--------+
|     |               |  key1  | key2 |   key3    | № | name  | age | isStud |
|     |               +--------+------+-----------+---+-------+-----+--------+
| val | 1, two, false |        |      | nestedKey | 1 | John  |  30 | false  |
|     |               | value1 |  789 +-----------+---+-------+-----+--------+
|     |               |        |      | nestedVal | 2 | Alice |  25 | true   |
+-----+---------------+--------+------+-----------+---+-------+-----+--------+

License

MIT

See also

  • Use this app to render JSON responses as tables in your browser by WebMaid
  • Simple build automation tool mk