https://github.com/gromnan/php-crunch-json
Optimizes JSON responses by minimizing duplication and improving compressibility.
https://github.com/gromnan/php-crunch-json
json json-crunch php-library
Last synced: 3 months ago
JSON representation
Optimizes JSON responses by minimizing duplication and improving compressibility.
- Host: GitHub
- URL: https://github.com/gromnan/php-crunch-json
- Owner: GromNaN
- Created: 2018-05-03T06:44:54.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-14T21:31:48.000Z (almost 8 years ago)
- Last Synced: 2025-08-19T03:56:07.842Z (11 months ago)
- Topics: json, json-crunch, php-library
- Language: PHP
- Size: 5.86 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
PHP implementation of the node module [`graphql-crunch`](https://github.com/banterfm/graphql-crunch#readme).
> Optimizes JSON responses by minimizing duplication and improving compressibility.
Installation
------------
```
composer require gromnan/json-crunch
```
How does it work?
-----------------
> We flatten the object hierarchy into an array using a post-order traversal of the object graph. As we traverse we efficiently check if we've come across a value before, including arrays and objects, and replace it with a reference to it's earlier occurence if we've seen it. Values are only ever present in the array once.
Usage
-----
```php
use function GromNaN\JsonCrunch\crunch;
$data = json_decode('{"a":["a","b","a"],"b":["a","b","a"]}');
$crunched = crunch($data);
echo json_encode($data, JSON_PRETTY_PRINT);
```
Result:
```json
[
"a",
"b",
[0,1,0],
{"a":2,"b":2}
]
```
Command-line
------------
```
bin/crunch-json
```