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.
npm install sjt.jsStructured 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.
[
{ "id": 1, "name": "Alice" },
{ "id": 2, "name": "Bob" }
][
[ ["id", "name"] ],
[ [1, "Alice"], [2, "Bob"] ]
]You can read the full specification here: https://github.com/SJTF/SJT/
- ✅ 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
import { encodeSJT, decodeSJT } from 'sjt.js';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);
}) Encodes structured JSON input into a compact SJT format.
Decodes SJT-encoded content back into original JSON.
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..
- The structure must be uniform across all entries
- Does not handle mixed schemas or optional fields (by design)
This library implements the full Structured JSON Table Specification v1.0.
| 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 |
-
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
- 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.
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.
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 }
]- ✅ 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.
Although SJT is represented as a nested array, it is a structured format with a strict schema, not a generic 2D array.
MIT © 2025 Yuki Akai