Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

jviotti/jsonbinpack-poc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

6e84a1d · Jul 22, 2022
Oct 19, 2021
Apr 2, 2022
Feb 8, 2022
Feb 14, 2022
Apr 2, 2022
Dec 29, 2021
Oct 19, 2021
Feb 14, 2022
Jun 24, 2021
Apr 14, 2021
Feb 19, 2021
Sep 9, 2021
Jun 5, 2021
Feb 14, 2022
May 31, 2021
Jun 24, 2021
Feb 19, 2021
Feb 14, 2022
Jul 22, 2022
May 31, 2021
Mar 30, 2022
Feb 14, 2022
Feb 14, 2022

GitHub Actions License PRs Welcome

JSON BinPack

JSON BinPack is an open-source binary JSON serialization format with a strong focus on space efficiency. It can run in schema-driven and schema-less mode to encode any JSON document given a matching JSON Schema 2020-12 definition.


NOTE! This is a prototype pre-production JavaScript-based implementation to prove the feasability of the approach. See https://github.com/sourcemeta/jsonbinpack for the work-in-progress C++ implementation.


Documentation

Installation

npm install --save jsonbinpack

Example

const jsonbinpack = require('jsonbinpack')

// Declare a JSON Schema definition
const schema = {
  $schema: 'https://json-schema.org/draft/2020-12/schema',
  type: 'object',
  properties: {
    foo: { type: 'string' }
  }
}

// (1) Compile the JSON Schema definition into an Encoding schema
const encodingSchema = await jsonbinpack.compileSchema(schema)

// (2) Serialize a matching JSON document using the Encoding schema
const buffer = jsonbinpack.serialize(encodingSchema, {
  foo: 'bar'
})

// (3) Deserialize the buffer into the original JSON document
const result = jsonbinpack.deserialize(encodingSchema, buffer)

console.log(result)
> { foo: 'bar' }

Reference

jsonbinpack.compileSchema(JSON Schema): Promise<Encoding>

Convert a JSON Schema definition into an Encoding schema for use with the .serialize() and .deserialize() functions.

jsonbinpack.serialize(Encoding, JSON): Buffer

Serialize a JSON value according to an Encoding schema.

jsonbinpack.deserialize(Encoding, Buffer): JSON

Deserialize a buffer according to an Encoding schema.

Building from source

Requirements:

  • Node.js
  • npm
  • GNU Make

Installing dependencies:

npm install

Compiling the project:

make
# Run tests
make test
# Run linter
make lint

License

This project is released under the terms specified in the license.