All Projects → pubkey → Jsonschema Key Compression

pubkey / Jsonschema Key Compression

Licence: apache-2.0
Compress json-data based on its json-schema while still having valid json

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Jsonschema Key Compression

Nano Sql
Universal database layer for the client, server & mobile devices. It's like Lego for databases.
Stars: ✭ 717 (+1115.25%)
Mutual labels:  json, nosql
Spectral
A flexible JSON/YAML linter for creating automated style guides, with baked in support for OpenAPI v2 & v3.
Stars: ✭ 876 (+1384.75%)
Mutual labels:  json-schema, json
Quicktype
Generate types and converters from JSON, Schema, and GraphQL
Stars: ✭ 7,459 (+12542.37%)
Mutual labels:  json-schema, json
Laravel Schemaless Attributes
Add schemaless attributes to Eloquent models
Stars: ✭ 595 (+908.47%)
Mutual labels:  json, nosql
Oakdex Pokedex
Ruby Gem and Node Package for comprehensive Generation 1-7 Pokedex data, including 809 Pokémon, uses JSON schemas to verify the data
Stars: ✭ 44 (-25.42%)
Mutual labels:  json-schema, json
Jsonschema2pojo
Generate Java types from JSON or JSON Schema and annotate those types for data-binding with Jackson, Gson, etc
Stars: ✭ 5,633 (+9447.46%)
Mutual labels:  json-schema, json
Lib
single header libraries for C/C++
Stars: ✭ 866 (+1367.8%)
Mutual labels:  json, compression
Sleekdb
Pure PHP NoSQL database with no dependency. Flat file, JSON based document database.
Stars: ✭ 450 (+662.71%)
Mutual labels:  json, nosql
Uvicorn Gunicorn Fastapi Docker
Docker image with Uvicorn managed by Gunicorn for high-performance FastAPI web applications in Python 3.6 and above with performance auto-tuning. Optionally with Alpine Linux.
Stars: ✭ 1,014 (+1618.64%)
Mutual labels:  json-schema, json
Brutusin Rpc
Self-describing JSON-RPC web services over HTTP, with automatic API description based on JSON-Schema
Stars: ✭ 36 (-38.98%)
Mutual labels:  json-schema, json
Full Stack Fastapi Postgresql
Full stack, modern web application generator. Using FastAPI, PostgreSQL as database, Docker, automatic HTTPS and more.
Stars: ✭ 7,635 (+12840.68%)
Mutual labels:  json-schema, json
Java Client Api
Java client for the MarkLogic enterprise NoSQL database
Stars: ✭ 52 (-11.86%)
Mutual labels:  json, nosql
Json Forms
JSON Schema to HTML form generator, supporting dynamic subschemas (on the fly resolution). Extensible and customizable library with zero dependencies. Bootstrap add-ons provided
Stars: ✭ 549 (+830.51%)
Mutual labels:  json-schema, json
Conf
Simple config handling for your app or module
Stars: ✭ 707 (+1098.31%)
Mutual labels:  json-schema, json
Jsonforms
Customizable JSON Schema-based forms with React, Angular and Vue support out of the box.
Stars: ✭ 542 (+818.64%)
Mutual labels:  json-schema, json
Movement
Movement is an easier, simpler way to explore and use NIEM. Want to join the Movement and contribute to it? Start here.
Stars: ✭ 19 (-67.8%)
Mutual labels:  json-schema, json
Tinydb
TinyDB is a lightweight document oriented database optimized for your happiness :)
Stars: ✭ 4,713 (+7888.14%)
Mutual labels:  json, nosql
Plank
A tool for generating immutable model objects
Stars: ✭ 449 (+661.02%)
Mutual labels:  json-schema, json
Fastapi
FastAPI framework, high performance, easy to learn, fast to code, ready for production
Stars: ✭ 39,588 (+66998.31%)
Mutual labels:  json-schema, json
Univalue
High performance RAII C++ JSON library and universal value object class
Stars: ✭ 46 (-22.03%)
Mutual labels:  json-schema, json

jsonschema-key-compression

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.

For example this:


{
    "firstName": "Corrine",
    "lastName": "Ziemann",
    "title": "Ms.",
    "gender": "f",
    "zipCode": 75963,
    "countryCode": "en",
    "birthYear": 1960,
    "active": false,
    "shoppingCartItems": [
        {
            "productNumber": 29857,
            "amount": 1
        },
        {
            "productNumber": 53409,
            "amount": 6
        }
    ]
}

becomes this:

{
    "|e": "Corrine",
    "|g": "Ziemann",
    "|j": "Ms.",
    "|f": "f",
    "|k": 75963,
    "|d": "en",
    "|c": 1960,
    "|a": false,
    "|i": [
        {
            "|h": 29857,
            "|b": 1
        },
        {
            "|h": 53409,
            "|b": 6
        }
    ]
}

Efficiency

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

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 intel i7 CPU.

  • Creating a compression-table from the schema of the object above takes about 0.02ms
  • Compressing the example-object from above takes about 0.021ms
  • Decompressing takes about 0.027ms 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
} from 'jsonschema-key-compression';
const compressionTable = createCompressionTable(jsonSchema);

compressObject

Compress a json-object based on its schema.

import {
    compressObject
} from 'jsonschema-key-compression';
const compressedObject = compressObject(
    compressionTable,
    jsonObject
);

decompressObject

Decompress a compressed object.

import {
    decompressObject
} from 'jsonschema-key-compression';
const jsonObject = decompressObject(
    compressionTable,
    compressedObject
);

compressedPath

Transform a chain of json-attributes into its compressed format.

import {
    compressedPath
} from 'jsonschema-key-compression';
const compressed = compressedPath(
    compressionTable,
    'whateverNested.firstName'
); // > '|a.|b'

decompressedPath

Decompress a compressed path.

import {
    decompressedPath
} from 'jsonschema-key-compression';
const decompressed = decompressedPath(
    compressionTable,
    '|a.|b' // from compressedPath
); // > 'whateverNested.firstName'

compressQuery

Compress a mango-query so that it can run over a NoSQL-database that has stored compressed documents.

import {
    compressQuery
} from 'jsonschema-key-compression';
const compressed = compressQuery(
    compressionTable,
    {
        selector: {
            active: {
                $eq: true
            }
        },
        skip: 1,
        limit: 1,
        fields: [
            'id',
            'name'
        ],
        sort: [
            'name'
        ]
    }
);
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].