pubkey/jsonschema-key-compression — dự án dữ liệu — đang có 103 sao GitHub trong nhóm Data. Compress json-data based on its json-schema while still having valid json
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Compress json-data based on its json-schema while still having valid json.
It works by compressing long attribute-names into smaller ones and backwards.
The efficiency depends on the amount and length of the attribute names.
The uncompressed json-object from above has about 230 chars as string
With the key-compression, this can be reduced to 140 chars which saves about 40%
Just using gzip on the json would result in 180 chars
Using gzip+key-compression ends in a string with only 127 chars
The enum-compression saves additional space,
the longer the values of the enums are the more it saves.
You can reproduce these results by running npm run test:efficiency.
Performance
The compression works pretty fast. Here are some time measurements on a single CPU core of a Node.js 22 process. Only the measured operation is timed, the creation of the test-data is not part of the measurement.
Creating a compression-table from the schema of the object above takes about 0.005ms
Compressing the example-object from above takes about 0.0025ms
Decompressing takes about 0.002ms per object
You can reproduce these results by running npm run test:performance.
You should use this when
you want to save storage space in an NoSQL-database but still want to have valid queryable json-data
you transmit many objects in many small requests over the network so that gzip cannot be efficient
you want to store json-data inside of the browser-storage (indexedDB or localstorage) and you reach the storage limit
You should NOT use this when
you send many objects in a single request, you should rely on gzip instead
you do not want to still have valid json-data, you should use protobuf instead
you have schema-less data
Comparison with gzip
Gzip generates its compression-flags from the input. This makes it more efficient, the more data is compressed at once. But gzip is less efficient the smaller the dataset is.
The key-compression creates the compression-table from the jsonschema up front with has advantages when small pieces of data are compressed.
Usage
Install
npm install jsonschema-key-compression --save
createCompressionTable
Creates a compression-table from the json-schema.
import {
createCompressionTable,
DEFAULT_COMPRESSION_FLAG
} from 'jsonschema-key-compression';
const compressionTable = createCompressionTable(jsonSchema);
// all parameters
const compressionTable = createCompressionTable(
jsonSchema,
DEFAULT_COMPRESSION_FLAG, // the character that marks a compressed key
['myProperty'], // property-names that must not be compressed
true // enable the enum-compression, see below
);
Enum-compression
Enum-compression stores the value of a property as the index of that value
inside of the enum of the property. With the enum ['admin', 'editor', 'viewer']
the value 'editor' is stored as the number 1.
It is opt-in with the fourth parameter of createCompressionTable(),
so that data which was compressed without it stays readable.
A property is only enum-compressed when it is safe to do so:
All values of the enum must be strings. A number inside of the enum could not be
told apart from an index, and strings are where the saved space is.
The property name must have the same enum everywhere in the schema.
A name that is used with different enums, or that has no enum somewhere else,
is left alone because the same number would otherwise mean different things.
Properties in ignoreProperties are not enum-compressed.
The enum-values are sorted before the indexes are assigned, so the order of the indexes
is the alphabetical order of the values. Because of this, sort and the range-operators
$gt, $gte, $lt and $lte keep working on compressed data.
compressQuery() also transforms the values of $eq, $ne, $in, $nin, $all,
$not and $elemMatch, and resolves a $regex into the $in of the matching indexes.
The operators $type and $mod are not transformed, they would run on the
number of the compressed value.
Enum-compression assumes that the data matches the schema.
A document that stores a number where the schema defines an enum of strings
cannot be told apart from an already compressed value.
Đọc thêm về pubkey/jsonschema-key-compression ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/pubkey/jsonschema-key-compression là nguồn chính thức.
pubkey/jsonschema-key-compression có bao nhiêu sao?
pubkey/jsonschema-key-compression có 103 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/pubkey/jsonschema-key-compression. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
pubkey/jsonschema-key-compression có những chủ đề gì?
GitHub topics của pubkey/jsonschema-key-compression: "compression", "json", "json-schema", "jsonschema", "nosql". TopGit xếp repo vào nhóm Data.
pubkey/jsonschema-key-compression có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho pubkey/jsonschema-key-compression. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
pubkey/jsonschema-key-compression còn đang phát triển không?
Commit gần nhất trên pubkey/jsonschema-key-compression là 13 ngày trước (theo timestamp GitHub). Repo có 11 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
pubkey/jsonschema-key-compression dùng license gì?
pubkey/jsonschema-key-compression phát hành theo license Apache-2.0. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
pubkey/jsonschema-key-compression viết bằng ngôn ngữ gì?
pubkey/jsonschema-key-compression chủ yếu viết bằng TypeScript. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
jsonschema-key-compression có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về jsonschema-key-compression.