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

jsonh

v0.0.6

Published

[JSONH](http://webreflection.blogspot.com/2011/08/last-version-of-json-hpack.html) - JSON Homogeneous Collections Compressor ============================================================================================================================

Downloads

9,169

Readme

JSONH - JSON Homogeneous Collections Compressor

donate

What is JSONH

JSONH is one of the most performant, yet safe, cross programming language, way to pack and unpack generic homogenous collections. Based on native or shimmed JSON implementation, JSONH is nothing different than a procedure performed right before JSON.stringify(data) or right after JSON.parse(data)

It is demonstrated that overall performances of JSONH are up to 3 times faster in compression and 2 times in parsing thanks to smaller and simplified nature of the collection/string.

It is also demonstrated that resulting bandwidth size will be incrementally smaller than equivalent JSON operation reaching, in certain cases, down to 30% of original size and without gzip/deflate compression in place.

JSONH is the latest version of json.hpack project and based on JSONDB concept.

New in version 0.0.2 ( JS only )

  • added experimental and optional schema argument at the end of all methods in order to parse automatically one or more nested homogenous collections
  • covered via unit tests pack/unpack with or without the usage of a schema

What is an Homogenous Collection

Usually a database result set, stored as list of objects where all of them contains the same amount of keys with identical name. This is a basic homogeneous collection example:

[
  {"a":"A","b":"B"},
  {"a":"C","b":"D"},
  {"a":"E","b":"F"}
]

We all have exchange over the network one or more homogenous collections at least once. JSONH is able to pack the example into [2,"a","b","A","B","C","D","E","F"] and unpack it into original collection at light speed.

JSONH is suitable for

  • runtime data compression with or without gzip/deflate on both client and server side
  • creation of static JavaScript files to serve in order to save space on Hard Drive and eventually make runtime gzip/deflate compression easier (smaller input)
  • send huge collection of data from the client to the server and improving performances over JSON.stringify(data) and required network bandwidth

If the generic object/data contains one or more homogenous collections, JSONH is suitable for these cases too via pack and unpack operations. Please read the related post to know more.

JSONH API

Every implementation is suitable for the programming language code style and every method supports original JSON signature. As example the JavaScript version is a global JSONH object with stringify, parse, pack, and unpack methods.

The python version is a module similar to json one with current methods: dump, dumps, load, loads, pack, and unpack.

import jsonh

print(jsonh.dumps(
    [{"a": "A", "b": "B"}, {"a": "C", "b": "D"}, {"a": "E", "b": "F"}],
    separator = (',',':')
))

The php 5 version is a static class plus some function in order to let developers decide for their favorite stile. Extra arguments accepted by json_encode and json_decode are supported as well.

require_once('JSONH.class.php');

// classic style
jsonh_encode($object); // jsonh_decode($str)

// static public style
JSONH::stringify($object); // JSONH::parse($str);

// singleton style
JSONH()->stringify($object); // JSONH()->parse($str)

TODO

  • clean up locally tests and use a standard one able to cover all aspects per each implementation
  • C# version, and hopefully with other developers help other languages too
  • simplified yet cross platform way to map hybrid objects, specifying via white list one or more nested properties to pack on stringify, and unpack on parse (automated and addressed compression for complex objects)

JavaScript And Native JSON Escape Problems

As @garethheyes pointed out by in this post, native JSON.stringify(data) may produce invalid JavaScript. Since JSONH aim is not to change native JSON behavior, neither is JSONH a replacement for JSON, all I can suggest is to perform this replacement when and if data could be corrupted:

JSONH.stringify(data).replace(
    /\u2028|\u2029/g,
    function (m) {
        return "\\u202" + (m === "\u2028" ? "8" : "9");
    })

This will ensure proper escape for those characters plus performances will be still better thanks to reduced string output size (compared with the equivalent operation performed by JSON.stringify(data)).