https://github.com/dial-once/node-json-minifier
A two-way JSON minifier to reduce JSON size and amount of data transferred on clients. Can also act as an obfuscator.
https://github.com/dial-once/node-json-minifier
json minifier obfuscator
Last synced: about 2 months ago
JSON representation
A two-way JSON minifier to reduce JSON size and amount of data transferred on clients. Can also act as an obfuscator.
- Host: GitHub
- URL: https://github.com/dial-once/node-json-minifier
- Owner: dial-once
- License: gpl-2.0
- Created: 2015-09-30T10:34:56.000Z (over 9 years ago)
- Default Branch: develop
- Last Pushed: 2018-11-30T08:50:31.000Z (over 6 years ago)
- Last Synced: 2025-03-11T11:43:55.115Z (2 months ago)
- Topics: json, minifier, obfuscator
- Language: JavaScript
- Size: 25.4 KB
- Stars: 6
- Watchers: 8
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-json-minifier
[](http://sonar.dialonce.net/dashboard?id=node-json-minifier)
[](http://sonar.dialonce.net/dashboard?id=node-json-minifier)
[](http://sonar.dialonce.net/dashboard?id=node-json-minifier)
[](http://proxy.dialonce.net/sonar/api/badges/measure?key=node-json-minifier&metric=coverage)
[](http://sonar.dialonce.net/dashboard?id=node-json-minifier)
[](http://sonar.dialonce.net/dashboard?id=node-json-minifier)A two-way JSON minifier to reduce JSON size and amount of data transferred on clients. Can also act as an obfuscator.
# how to use
```npm install json-minifier```
## Compressor
```js
var specs = {
key: 'k',
MySuperLongKey: 'm',
SomeAnotherPropertyThatIsRealyLong: 's'
};var minifier = require('json-minifier')(specs);
var json = minifier.minify({
SomeAnotherPropertyThatIsRealyLong: 1234,
MySuperLongKey: 'Home',
key: 0
});/*
{ s: 1234,
m: 'Home',
k: 0 }
*/
console.log(json);
```## Uncompressor
Using the json object from the previous exemple:
```js
/*
{
SomeAnotherPropertyThatIsRealyLong: 1234,
MySuperLongKey: 'Home',
key: 0
}
*/
console.log(minifier.unminify(json));
```### Use in browser
You can implement your own, don't need to require our module or use browserify. Use the following snippet:```json``` is your compressed json, and you exposed your compression table in the ```reverseJsonFilters``` array.
```js
function unzip(json) {
for (var key in json) {
if (typeof json[key] === 'object') {
unzip(json[key]);
}
if (reverseJsonFilters[key] !== undefined) {
json[reverseJsonFilters[key]] = json[key];
delete json[key];
}
}
}
```