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

joyson

v1.0.5

Published

JOYFUL JSON | A smarter approach to serialize more than JSON, faster than ever!

Downloads

50

Readme

JOYSON - JSON

| Feature | JOYSON | CBOR | MessagePack | FlexBuffers | |------------------------------------------|:------:|:----:|:-----------:|:-----------:| | Nullish (null, undefined) | ✅ | ✅ | ✅ | ⚠️ | | Strings | ✅ | ✅ | ✅ | ✅ | | Numbers | ✅ | ✅ | ✅ | ✅ | | BigInt | ✅ | ✅ | ⚠️ | ❌ | | Objects | ✅ | ✅ | ✅ | ✅ | | Object Literals | ✅ | ✅ | ✅ | ✅ | | Arrays | ✅ | ✅ | ✅ | ✅ | | TypedArrays | ✅ | ❌ | ✅ | ✅ | | ArrayBuffers | ✅ | ❌ | ⚠️ | ✅ | | Dates | ✅ | ✅ | ✅ | ⚠️ | | Blobs | ❌ | ❌ | ❌ | ❌ | | Files | ❌ | ❌ | ❌ | ❌ | | Maps | ✅ | ✅ | ✅ | ⚠️ | | Sets | ✅ | ✅ | ✅ | ⚠️ | | Errors | ✅ | ✅ | ✅ | ⚠️ | | Regular Expressions | ✅ | ❌ | ⚠️ | ⚠️ | | Circular References | ✅ | ❌ | ⚠️ | ⚠️ | | Support Sharing ArrayBuffers | ✅ | ❌ | ❌ | ❌ |

| Feature | JOYSON | CBOR | MessagePack | FlexBuffers | |------------------------------------------|:------:|:----:|:-----------:|:-----------:| | Human-readable Format (like JSON) | ✅ | ❌ | ❌ | ❌ | | Compact Binary Format | ✅ | ✅ | ✅ | ✅ | | Performance with Complex Data Structures | ✅ | ⚠️ | ✅ | ✅ | | API Similar to JSON (stringify/parse) | ✅ | ❌ | ❌ | ❌ | | Efficiency (Processing Speed) | 140x | 1x | 140x | 70x |

Performance Discussion

JOYSON:

  • Performance: JOYSON excels in performance when dealing with TypedArrays and ArrayBuffers due to its `pack` and `unpack` methods. It uniquely supports the sharing of ArrayBuffers across objects, ensuring that when a TypedArray is shallow-copied, it remains linked across instances and is stored only once. This results in significant memory and speed optimizations for complex data structures.
  • API: JOYSON has a similar API to JSON, making it easy to use with `stringify` and `parse` methods. This simplicity, combined with high performance, makes it a prodigious tool for developers needing efficient serialization and deserialization.

CBOR:

  • Performance: CBOR is designed for small code size and high efficiency. However, it does not support all TypedArrays and ArrayBuffers, which limits its performance with these specific data types. It is considerably slower than JOYSON and MESSAGEPACK
  • API: CBOR focuses on compact binary representation but lacks a JSON-like API, which can make it less intuitive for developers familiar with JSON.

MessagePack:

  • Performance: MessagePack provides equaling efficient serialization and deserialization speed compared to Joyson. It supports TypedArrays and ArrayBuffers, but it does not support the sharing of ArrayBuffers across objects or shallow copying of TypedArrays, so that means that all TypedArray's subarray are copied the wrong way.
  • API: It has a different API from JSON, which might require additional learning for developers used to JSON methods.

FlexBuffers:

  • Performance: FlexBuffers offers high performance and flexibility, supporting TypedArrays and ArrayBuffers. However, similar to MessagePack, it does not support the sharing of ArrayBuffers across objects or shallow copying of TypedArrays.
  • API: FlexBuffers also has a unique API, distinct from JSON, which might require additional learning.

In summary, JOYSON stands out for its unique capabilities in handling complex data structures and memory optimization, along with a user-friendly JSON-like API, making it a versatile and high-performance choice for serialization and deserialization in JavaScript.

SECTION

Key Differences

  • Standard JSON Methods: stringify and parse convert objects to/from JSON strings.
  • Extended Binary Methods: pack and unpack handle serialization/deserialization of data into/from a compact binary format, beneficial for performance-intensive applications.

SECTION

Features

  • TypedArray Support: Seamless encoding and decoding of TypedArrays within JSON objects.
  • Memory Efficiency: Optimized for minimal memory footprint during processing.
  • Binary Serialization: The pack method allows for compact binary serialization of data, while unpack restores it, ensuring efficient data handling.

SECTION

Installation

Install joyson using npm:

npm install joyson

SECTION

Usage

Import JOYSON from joyson:

import JOYSON from 'joyson';

Using /dist/browser.min.js` enable you to directly use JOYSON like JSON

Encoding/Decoding an Object

const object = {test: "hello", data: [1, 23, 5, 6, {"##": undefined, "##test": /regex/i, date: new Date(), table: [-0, 111111111n, -666.777, new Set([1, 2, "blue", {}]), new Map()], arr: Int16Array.of(-6, 777, 12), arr2: new Uint8Array(9)}, "hello here is asaitama I love JS"]};
const encoded = JOYSON.stringify(object); // `{"test":"hello","data":[1,23,5,6,{"#$IyM=":"data:joyson/undefined;","#$IyN0ZXN0":"data:joyson/regexp;cmVnZXg=:aQ==","##date":"data:joyson/date;2023-12-25T00:33:37.935Z","table":["data:joyson/number;-0","data:joyson/bigint;111111111",-666.777,"data:joyson/set;WzEsMiwiYmx1ZSIse31d","data:joyson/map;W10="],"##arr":"data:joyson/int16array;base64,+v8JAwwA","##arr2":"data:joyson/uint8array;base64,AAAAAAAAAAAA"},"hello here is asaitama I love JS"]}`
const decoded = JOYSON.parse(encoded);

console.log(object, encoded, decoded);

Packing/Unpacking Data

const yourObject = {test: "hello", data: [1, 23, 5, 6, {arr: Int16Array.of(-6, 777, 12), arr2: new Uint8Array(9)}]};
const packedData = JOYSON.pack(yourObject); // Uint8Array of 151 Bytes
const unpackedData = JOYSON.unpack(packedData);

console.log(packedData, unpackedData);

SECTION

Introducing JOYSON, the versatile NPM library that excels in supporting all typed arrays—a feature that is lacking in CBOR, BSON, and various other libraries. With JOYSON, you gain the advantage of support for ArrayBuffer that are shared across typed arrays. JOYSON stores typed arrays and buffers separately, ensuring proper references and seamless data handling.

Dive into the robust capabilities of JOYSON, which fully understands the critical aspects of serialization for a wide range of data structures, including RegExp, Errors, Sets, Maps, Dates, ArrayBuffer, TypedArray, Arrays, Object Literals, Objects, BigInt, standard Numbers, complex Numbers, Strings, special character strings, nullish values, and more.

While JOYSON is slightly less fast (-10%) than MessagePacker when processing mixed values, it significantly outperforms with big typed arrays, boasting a +30% increase in speed compared to messagepacker. And of course, when compared to CBOR, BSON, structured clone, and others, MessagePacker is much faster, but JOYSON is the library that combines speed with versatility and comprehensive data type support.