npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@tabular-json/tabular-json

v1.1.1

Published

Tabular-JSON: a superset of JSON with CSV-like tables

Readme

Tabular-JSON: JSON with tables

Tabular-JSON is:

  • a replacement for CSV without its ambiguities and limitation to tabular data structures
  • a replacement for JSON without its verbosity with tabular data

Learn more:

Here is an example of Tabular-JSON:

{
  "name": "rob",
  "hobbies": [
    "swimming",
    "biking",
  ],
  "friends": ---
    "id", "name",  "address"."city", "address"."street"
    2,    "joe",   "New York",       "1st Ave"
    3,    "sarah", "Washington",     "18th Street NW"
  ---,
  "address": {
    "city": "New York",
    "street": "1st Ave",
  }
}

JavaScript API

Install

Install using npm:

npm install @tabular-json/tabular-json

Use

import { parse, stringify } from '@tabular-json/tabular-json'

const text = `{
  "id": 1,
  "name": "Brandon",
  "friends": ---
    "id", "name"
    2,    "Joe"
    3,    "Sarah"
  ---
}`

const data = parse(text)

data.friends.push({ id: 4, name: 'Alan' })

const updatedText = stringify(data, {
  indentation: 2,
  trailingCommas: false
})
// {
//   "id": 1,
//   "name": "Brandon",
//   "friends": ---
//     "id", "name"
//     2,    "Joe"
//     3,    "Sarah"
//     4,    "Alan"
//   ---
// }

API

type parse = (text: string) => unknown

type stringify = (json: unknown, options?: StringifyOptions) => string

interface StringifyOptions {
  indentation?: number | string
  trailingCommas?: boolean
  outputAsTable?: <T>(tabularData: Tabular<T>) => boolean
}

The option outputAsTable is explained in detail in the section Output as table below.

Output as table

Data is tabular when it is an array containing at least one item, where every item is an object. Stringifying tabular data as a table normally results in the smallest output, but it is not always the most readable way. For example having nested tables inside a table is not very readable. Also, having a table containing a field like "comments" or "description" which contains long texts results in a very wide column, making the formatted table hard to read.

Depending on your use case, you can configure a strategy for when to output tabular data as a table. This can be done using the option outputAsTable. The function outputAsTable is invoked for all tabular data in the input json and returns true when the data should be stringified as a table.

The tabular-json library comes with a number of built-in utility functions that can be used with outputAsTable:

  • always(tabularData): always serialize tabular data as a table, also when the data contains nested arrays. This is the default value of option outputAsTable.
  • noNestedArrays(tabularData): serialize tabular data as a table when the data does not contain nested arrays.
  • noNestedTables(tabularData): serialize tabular data as a table when the data does not contain nested tables. Allows nested arrays when the contain primitive values like numbers or strings.
  • isHomogeneous(tabularData): serialize tabular data as a table when the structure is homogeneous, that is every item has the exact same keys and nested keys.
  • noLongStrings(tabularData [, maxLength]): serialize tabular data as a table when the data does not contain long text fields

There an example:

import { stringify, noLongStrings } from 'tabular-json'

const data = {
  careTakers: [
    { id: 1001, name: 'Joe' },
    { id: 1002, name: 'Sarah' }
  ],
  animals: [
    {
      animalId: 1,
      name: 'Elephant',
      description: 'Elephants are the largest living land animals.'
    },
    {
      animalId: 2,
      name: 'Giraffe',
      description: 'The giraffe is the tallest living terrestrial animal on Earth'
    }
  ]
}

// Use the default table strategy
console.log(stringify(data, { indentation: 2 }))
// {
//   "careTakers": ---
//     "id", "name"
//     1001, "Joe"
//     1002, "Sarah"
//   ---,
//   "animals": ---
//     "animalId", "name",     "description"
//     1,          "Elephant", "Elephants are the largest living land animals."
//     2,          "Giraffe",  "The giraffe is the tallest living terrestrial animal on Earth"
//   ---
// }

// Do not output tables containing long strings as table
const maxLength = 20
console.log(
  stringify(data, {
    indentation: 2,
    outputAsTable: (tabularData) => noLongStrings(tabularData, maxLength)
  })
)
// {
//   "careTakers": ---
//     "id", "name"
//     1001, "Joe"
//     1002, "Sarah"
//   ---,
//   "animals": [
//     {
//       "animalId": 1,
//       "name": "Elephant",
//       "description": "Elephants are the largest living land animals."
//     },
//     {
//       "animalId": 2,
//       "name": "Giraffe",
//       "description": "The giraffe is the tallest living terrestrial animal on Earth"
//     }
//   ]
// }

Besides using the build-in examples, You can implement your own function to determine when to output tabular data as a table. If you have multiple tables and only some of them must be serialized as table, you can for example write some logic to determine which table you're dealing with by looking at the fields of the first item of the array:

function isAnimalTable(tabularData) {
  return 'animalId' in tabularData[0]
}

// Using the same data as in the previous example
console.log(
  stringify(data, {
    indentation: 2,
    outputAsTable: (tabularData) => !isAnimalTable(tabularData)
  })
)
// {
//   "careTakers": ---
//     "id", "name"
//     1001, "Joe"
//     1002, "Sarah"
//   ---,
//   "animals": [
//     {
//       "animalId": 1,
//       "name": "Elephant",
//       "description": "Elephants are the largest living land animals."
//     },
//     {
//       "animalId": 2,
//       "name": "Giraffe",
//       "description": "The giraffe is the tallest living terrestrial animal on Earth"
//     }
//   ]
// }

Test Suite

There is a JSON based Test Suite available that can be used to ensure that implementations of Tabular-JSON match the official specification, see Tabular-JSON Test Suite.