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

sjt.js

v1.1.1

Published

Structured JSON Table implementation for TypeScript/JS.

Readme

SJT.js

NPM Version NPM Downloads

Build Status codecov

🚀 Fast and lightweight encoder/decoder for Structured JSON Table (SJT)

SJT.js is a JavaScript implementation of the Structured JSON Table (SJT) Specification. It provides an efficient way to compress repetitive JSON structures, particularly arrays of uniform objects, into a compact, schema-driven table format.


🔧 Install

npm install sjt.js

🧠 What is SJT?

Structured JSON Table (SJT) is a compact, schema-first data representation for JSON-like objects. It allows structured and efficient serialization/deserialization of deeply nested objects — making it ideal for storing, diffing, or transmitting data in a table-like format.

Example

Input:

[
  { "id": 1, "name": "Alice" },
  { "id": 2, "name": "Bob" }
]

Encoded:

[
  [ ["id", "name"] ],
  [ [1, "Alice"], [2, "Bob"] ]
]

You can read the full specification here: https://github.com/SJTF/SJT/


📦 Features

  • ✅ Supports nested objects and arrays
  • ✅ Supports array of objects, arrays of primitives
  • ✅ Schema-defined (header + data)
  • ✅ Deterministic encoding and decoding
  • ✅ Works with deeply nested structures
  • ✅ Fast and lightweight, no external dependencies
  • ✅ Supports both CommonJS and ESM

✨ Usage

ESM

import { encodeSJT, decodeSJT } from 'sjt.js';

CJS

const { encodeSJT, decodeSJT } = require('sjt.js');

Then

//server

const data = [
  { id: 1, name: "Alice" },
  { id: 2, name: "Bob" }
];

const compressedJson = encodeSJT(data);

client.send(compressedJson);


//client
fetch('http://you-server').then((res) => {
const restored = decodeSJT(res.json());
console.log(restored);
}) 

🧪 API

encodeSJT(input: any): [header: any, data: any]

Encodes structured JSON input into a compact SJT format.

decodeSJT([header, data]: [any, any]): any

Decodes SJT-encoded content back into original JSON.


🖐 Why

SJT is ideal for data transmission where reducing bandwidth is crucial, especially for APIs returning large arrays of similarly structured objects. SJT reduces payload size even without relying on gzip, and compresses even better when used alongside gzip..


⚠ Limitations

  • The structure must be uniform across all entries
  • Does not handle mixed schemas or optional fields (by design)

📑 Specification

This library implements the full Structured JSON Table Specification v1.0.


📊 Benchmark Comparison (Full Encode/Decode)

| Format | Size (KB) | Encode Time | Decode Time | |----------------|-----------|-------------|-------------| | JSON | 3849.34 | 41.81 ms | 51.86 ms | | JSON + Gzip | 379.67 | 55.66 ms | 39.61 ms | | MessagePack | 2858.83 | 51.66 ms | 74.53 ms | | SJT (json) | 2433.38 | 36.76 ms | 42.13 ms | | SJT + Gzip | 359.00 | 69.59 ms | 46.82 ms |

🔍 Notes:

  • SJT outperforms JSON in both size and speed (encode/decode), and compresses even better than MessagePack.

  • Compared to MessagePack, SJT is:

    • ~15% smaller
    • Faster in both encode and decode

🧪 Test Conditions:

  • Dataset: Large structured (50k record) object with nested arrays/objects
  • Benchmarked using Node.js 20
  • All sizes measured in uncompressed KB (binary formats estimated)

🚀 SJT offers a great balance between size and speed, making it ideal for transmitting structured data efficiently.


⚡ Why is SJT faster than regular JSON?

Although SJT is still transported as JSON (via JSON.stringify / JSON.parse), its structural design allows it to outperform standard row-based JSON arrays during parsing and transformation.

✅ Core reason: columnar layout

Instead of representing each record as an object, SJT stores values by columns:

// SJT format
[
  ["id", "name", "age"],                    // header
  [[1, 'Alice', 25], [2, 'Bob', 30]]      // data by column
]

// Regular JSON
[
  { "id": 1, "name": "Alice", "age": 25 },
  { "id": 2, "name": "Bob", "age": 30 }
]

🔍 Performance advantages:

  • Fewer key lookups: Engines don’t repeatedly parse and compare key strings like "id" and "name" for every row.
  • Batch-friendly decode: Data can be reconstructed with linear loops, avoiding per-object overhead.
  • Better CPU cache locality: Arrays grouped by type are more cache-efficient than scattered key-value pairs.
  • No key-matching logic needed: All columns align perfectly with the header—no missing or extra keys to check.

⚠️ Important:

Although SJT is represented as a nested array, it is a structured format with a strict schema, not a generic 2D array.


📋 License

MIT © 2025 Yuki Akai