Download the PHP package inkrot/php-compress-json without Composer
On this page you can find all versions of the php package inkrot/php-compress-json. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download inkrot/php-compress-json
More information about inkrot/php-compress-json
Files in inkrot/php-compress-json
Package php-compress-json
Short Description Store JSON data in space efficient manner
License BSD-2-Clause
Homepage http://github.com/inkrot/php-compress-json
Informations about the package php-compress-json
php-compress-json
A PHP library to compress large JSON documents with repeated structures and values. Helps to reduce the size of a JSON file, for example, during storage or transmission over the network, while preserving the document structure and key names.
Inspired by compress-json. And thanks to @beenotung.
This library is fully compatible with compress-json for NodeJS.
Features
- Supports all JSON types
- Object key order is preserved
- Repeated values are stored only once
- Numbers are encoded in base62 format (0-9A-Za-z)
- Custom Memory providers for store and cache during compress heavy data (see class AbstractMemory).
You can pass your custom memory provider through the
Compressor::createWithMemory()method - Passing custom
json_encodeorjson_decodearguments intoJsonordecompressJsonmethods respectively
Special Values
The following special values are supported (v3.2.0 compatibility):
| Value | Encoded |
|---|---|
null |
'' (empty string) |
true |
b\|T |
false |
b\|F |
INF (Infinity) |
N\|+ |
-INF (-Infinity) |
N\|- |
NAN (Not a Number) |
N\|0 |
Example:
Install
Via Composer
Usage
Compress
Output:
Decompress
Output:
Example structure for efficient compression
Pure JSON (749 chars)
Compressed JSON (562 chars)
In this example, compression gives an efficiency of 25%. However, the more complex and repetitive the structure, the greater the compression efficiency.
Testing
Credits
License
BSD 2-Clause License (Free Open Sourced Software)