1.0.3 • Published 3 months ago

joyson v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

JOYSON

JOYSON LOGO

joyson is a JavaScript module designed for efficient encoding and decoding of JSON objects, particularly adept at handling TypedArrays. Unlike standard JSON methods, joyson provides additional pack and unpack methods for more memory-efficient handling of large data structures, including support for binary data serialization.

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.

1.0.3

3 months ago

1.0.2

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago

0.18.1

4 months ago

0.18.2

4 months ago

0.14.0

4 months ago

0.16.0

4 months ago

0.17.0

4 months ago

0.18.0

4 months ago

0.12.11

4 months ago

0.12.12

4 months ago

0.12.10

4 months ago

0.8.5

4 months ago

0.8.4

4 months ago

0.12.7

4 months ago

0.12.8

4 months ago

0.12.9

4 months ago

0.11.0

4 months ago

0.12.0

4 months ago

0.12.1

4 months ago

0.12.2

4 months ago

0.12.3

4 months ago

0.12.4

4 months ago

0.12.5

4 months ago

0.12.6

4 months ago

0.10.0

4 months ago

0.9.0

4 months ago

0.8.1

4 months ago

0.8.0

4 months ago

0.7.1

4 months ago

0.9.2

4 months ago

0.9.1

4 months ago

0.8.2

4 months ago

0.7.0

4 months ago

0.6.1

4 months ago

0.6.0

4 months ago

0.5.0

4 months ago

0.4.1

4 months ago

0.4.0

4 months ago

0.3.0

4 months ago

0.2.3

4 months ago

0.2.2

4 months ago

0.2.1

4 months ago

0.2.0

4 months ago

0.1.0

4 months ago