npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jsonbinpack

v1.1.2

Published

A space-efficient schema-driven binary JSON serialization format based on JSON Schema

Downloads

22

Readme

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.

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

Contributing

Thanks for your interest in contributing to the project. We welcome contributions in any of the following areas:

  • Add more JSON + JSON Schema test cases in the test/e2e directory
  • Improve the documentation at docs
  • Suggesting new encodings to make JSON BinPack more space-efficient
  • Performance improvements, primarily in the encoder
  • General bug fixes

Additionally, we are tracking the following major changes:

  • [ ] Re-write the encoders in C++ and compile to WebAssembly
  • [ ] Generate serialization and deserialization C++ code that does not dynamically traverses the encoding schema for runtime performance reasons
  • [ ] Support recursive JSON Schema documents
  • [ ] Implement support for the if, then, and else JSON Schema keywords
  • [ ] Implement support for the anyOf JSON keyword
  • [ ] Implement support for inline binary blobs defined with the contentEncoding JSON Schema keyword

Don't hesitate in getting in touch by creating a ticket if you require any guidance on contributing to the project.

License

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