New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

compressed-json

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

compressed-json

String base JSON compressor

1.0.13
Source
npm
Version published
Maintainers
1
Created
Source

compressed-json

npm Version

String base JSON compressor

If you want seriously reduce your data size, consider using msgpack.

Use compressed-json only if you cannot handle binary for some reason.

Install

npm i compressed-json

Usage

'use strict'

const cjson = require('compressed-json')

// Convert json object
const compressed = cjson.compress({ /* Large json */ })
const restored = cjson.decompress(compressed)

// Convert json string

const compressedString = cjson.compress.toString({ /* Some large json */ })
const restoredFromString = cjson.decompress.fromString(compressedString)

How It Works

compressed-json has two logics:

Example compression

example-src.json

{
  "description": "This is example json",
  "entities": [
    {
      "id": 1,
      "name": "Dog",
      "desc": "This is desc of dog",
      "tag": ["animal"]
    },
    {
      "id": 1,
      "name": "Cat",
      "desc": "This is desc of cat",
      "tag": ["animal"]
    }
  ],
  "notes": [
    "Unique string will be kept as is",
    "Duplicated string will be combined",
    "Duplicated string will be combined",
    "p: string start with 'p:' will be escaped "
  ]
}

example-compressed.json

{
  "_": {
    "0": "This is example json",
    "1": [
      {
        "2": 1,
        "3": "Dog",
        "4": "This is desc of dog",
        "5": [
          "p:0"
        ]
      },
      {
        "2": 1,
        "3": "Cat",
        "4": "This is desc of cat",
        "5": [
          "p:0"
        ]
      }
    ],
    "6": [
      "Unique string will be kept as is",
      "p:1",
      "p:1",
      "e:p: string start with 'p:' will be escaped "
    ]
  },
  "K": [
    "description",
    "entities",
    "id",
    "name",
    "desc",
    "tag",
    "notes"
  ],
  "P": [
    "animal",
    "Duplicated string will be combined"
  ]
}

Structure of compressed json

KeyDescription
KArray of original keys
PPointed string values
_Compressed payload

Key-Compression logic

All object keys are replaced with index of array stored in K of compressed JSON.

String-Value-Pointing

String values appeared at least two will replaced with pointer string with contains index of array stored in P of compressed JSON.

Keywords

JSON

FAQs

Package last updated on 23 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts