JSPM

json-compressed

0.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q23944F
  • License ISC

A tool to compress and decompress arrays into a lighter json string, for AJAX requests

Package Exports

  • json-compressed

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (json-compressed) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

JSONc (JSON compressed)

A compressed way to parse objects/asociative arrays

How does it work?

When you have an associative array, it breaks into an array of keys, and array of values.

Small example:

{"data": [{"my_key": "my_val1"},{"my_key": "my_val2"},{"my_key": "my_val3"},{"my_key": "my_val4"},{"my_key": "my_val5"},{"my_key": "my_val6"},{"my_key": "my_val7"},{"my_key": "my_val8"},{"my_key": "my_val9"}]} = 209

Compressed:

{"data": {"keys": ["my_key"], "data":["my_val1","my_val2","my_val3","my_val4","my_val5","my_val6","my_val7","my_val8","my_val9"]}} = 130

Ratio: 130/209 = 62%

Big example (example/example.php):

Same ratio for 100, 1000, or 50000 rows. ~ 45% for fair data

Number of rows: 50,000

JSON Compressed size: 21.55MB

JSON size: 47.3MB

Compressed size compared to uncompressed size: 45.57%

Usage

    $.ajax({dataType: "jsonc"});
    header('Content-Type: application/x-jsonc');
    jsonc_encode($my_array, $my_keys);

Where $my_keys is an array of the keys that contain the associative arrays. In my example, just ["data"]

Dependencies

  • jQuery (code contains an ajax type extension)