README
Brick.Json
An algorithm for compress JSON, up to 15% better than Gzip
Installation
$ npm install brick.json
# or
$ yarn add brick.json
Usage
Basic
import { compress, decompress } from 'brick.json'
const data = [{a: 1, b: 2}, [1, 2, 3]]
const brickData = compress(data)
const res = decompress(brickData) // res is deep equal data
With Gzip
import { compressWithGzip, decompressWithGzip } from 'brick.json/gzip/cjs' // or esm
const data = [{a: 1, b: 2}, [1, 2, 3]]
const str = compressWithGzip(data) // type is string
const res = decompressWithGzip(str) // res is deep equal data
Background
Sometimes our browser will upload some data to the server, but as the sender, the browser does not know which compression algorithms are supported by the service, so by default the uploaded data is not compressed, which is why this solution exists. This lib used a cjson-like algorithms approach to de-weight duplicate keys to reduce the json size. As the compressed data resembles a lot of bricks 🧱🧱🧱, so it is named Brick.Json
How it's work
A raw JSON object like below
[
{
"a": "aa",
"b": "bb",
"c": "cc"
},
{
"a": "2A",
"b": {
"b": "B",
"c": "C",
"d": [
true,
null,
false
],
"a": "A"
}
}
]
After Brick.Json compress
[
[[1,"c"],["a","b"],[0,"d"]], // keys array -> [ abc, ab, abcd ]
["