# buffer-json-encoding

> An abstract-encoding compatible JSON encoder/decoder that properly encodes/decodes buffers.

Latest version **1.0.2** (published 2019-02-25) · ISC license · 0 weekly downloads

## Install

```sh
npm install buffer-json-encoding
pnpm add buffer-json-encoding
yarn add buffer-json-encoding
bun add buffer-json-encoding
```

## Health

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

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2019-02-25 |
| First published | 2019-02-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | separate (@types/buffer-json-encoding) |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | harry lachenmayer |
| Maintainers | lachenmayer |
| Keywords | json, json-buffer, buffer, abstract-encoding, encode, decode |

## Links

- npm: https://www.npmjs.com/package/buffer-json-encoding
- npm.io page: https://npm.io/package/buffer-json-encoding

## Dependencies (1)

- [buffer-json](https://npm.io/package/buffer-json.md) ^2.0.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.2 (latest) — 2019-02-25
- 1.0.1 — 2019-02-25
- 1.0.0 — 2019-02-14
- 0.1.0 — 2019-02-08

## README

# buffer-json-encoding

[![abstract-encoding](https://img.shields.io/badge/abstract--encoding-compliant-brightgreen.svg?style=flat)](https://github.com/mafintosh/abstract-encoding)

An [`abstract-encoding`](https://github.com/mafintosh/abstract-encoding) compatible JSON encoder/decoder that properly encodes/decodes buffers.

The reason this module exists is that JSON does not have a built-in data type for binary data, so Node.js by default encodes a buffer as an object of shape `{ type: "Buffer", data: [...] }`. The issue is that Node.js does not decode these objects as Buffer instances, which is not very useful if you actually want to do something with them.

This module depends on [`buffer-json`](https://www.npmjs.com/package/@lachenmayer/buffer-json) which provides a [_replacer_](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter) & [_reviver_](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse) for use with `JSON.stringify` & `JSON.parse` respectively. Buffer data is encoded as a base64-encoded string, rather than as an array of numbers. Buffers are decoded as expected with both (base-64 & array) encodings.

## API

```
buffer = encode(obj, [buffer], [offset])
obj = decode(buf, [start], [end])
number = encodingLength(obj)
```

See [`abstract-encoding`](https://github.com/mafintosh/abstract-encoding) for more details.

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