# json-shrink

> shrink json objects with LZMA (7-zip) or Brotli compression + jsonpack

Latest version **0.0.124** (published 2022-04-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install json-shrink
pnpm add json-shrink
yarn add json-shrink
bun add json-shrink
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.124 |
| Published | 2022-04-16 |
| First published | 2021-03-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 6.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | stonkpunk |
| Maintainers | stonkpunk |
| Keywords | compression, compress, jsonpack, lzma, 7zip, shrink, brotli |

## Links

- npm: https://www.npmjs.com/package/json-shrink
- Homepage: https://github.com/stonkpunk/my-npm-modules/tree/main/json-shrink
- npm.io page: https://npm.io/package/json-shrink

## Dependencies (3)

- [lzma](https://npm.io/package/lzma.md) ^2.3.2
- [brotli](https://npm.io/package/brotli.md) ^1.3.2
- [jsonpack](https://npm.io/package/jsonpack.md) ^1.1.5

## Alternatives

- [lodash.startswith](https://npm.io/package/lodash.startswith.md) — 769.7K weekly downloads
- [@tarojs/service](https://npm.io/package/@tarojs/service.md) — 33.9K weekly downloads
- [io.extendreality.tilia.indicators.spatialtargets.unity](https://npm.io/package/io.extendreality.tilia.indicators.spatialtargets.unity.md) — 131 weekly downloads
- [@rtarojs/taro](https://npm.io/package/@rtarojs/taro.md) — 90 weekly downloads
- [node-branch-io](https://npm.io/package/node-branch-io.md) — 50 weekly downloads

## Recent versions

- 0.0.124 (latest) — 2022-04-16
- 0.0.123 — 2022-04-16
- 0.0.122 — 2022-04-05
- 0.0.121 — 2021-10-20
- 0.0.12 — 2021-03-17
- 0.0.11 — 2021-03-13
- 0.0.1 — 2021-03-13

## README

# json-shrink

shrink objects/json with LZMA (7-zip) or Brotli compression + optional [jsonpack](https://www.npmjs.com/package/jsonpack)

```javascript
var shrunken = shrink(obj, outputAsString = false, doPack = true, doUseBrotli = false);
var unshrunk = unshrink(shrunken, doUnPack = true, doUseBrotli = false);
```

## Installation

```sh
npm i json-shrink
```

## Usage




```javascript
var jsh = require('json-shrink');
var shrink = jsh.shrink;
var unshrink = jsh.unshrink;

//compressing json into buffer or string:
//shrink(obj, outputAsString = false, doPack = true, doUseBrotli=false)
var original_obj = {ok:"here is some text"};
var compressed_into_buffer = shrink(original_obj); //output as buffer
var compressed_into_string = shrink(original_obj, true); // output as base64 string

//uncompressing
//note - params used for uncompressing must align with the params used for compressing!
//unshrink(shrunken, doUnPack = true, doUseBrotli=false);
console.log("uncompressed str", unshrink(compressed_into_string));
console.log("uncompressed buffer", unshrink(compressed_into_buffer));

//result
//uncompressed str { ok: 'here is some text' }
//uncompressed buffer { ok: 'here is some text' }
```

## Usage - jsonpack disabled

```javascript
//with jsonpack disabled:
var compressed_buffer_nopack = shrink(original_obj, false, false);
var compressed_string_nopack = shrink(original_obj, true, false);

console.log("uncompressed str - no jsonpack", unshrink(compressed_string_nopack, false));
console.log("uncompressed buffer - no jsonpack", unshrink(compressed_buffer_nopack, false));

//result
//uncompressed str - no jsonpack { ok: 'here is some text' }
//uncompressed buffer - no jsonpack { ok: 'here is some text' }
```

## See Also

- [jsonfile-compressed](https://www.npmjs.com/package/jsonfile-compressed) - uses `json-shrink`

[![stonks](https://i.imgur.com/UpDxbfe.png)](https://www.npmjs.com/~stonkpunk)

---
_Source: https://npm.io/package/json-shrink · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
