# koa-json

> pretty (non-compressed) json response middleware

Latest version **2.0.2** (published 2016-04-28) · MIT license · 0 weekly downloads

## Install

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

## 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 | 2.0.2 |
| Published | 2016-04-28 |
| First published | 2014-02-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/koa-json) |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 198 |
| Maintainers | aheckmann, coderhaoxin, dead_horse, eivifj, fengmk2, jonathanong, jongleberry, juliangruber, tjholowaychuk |
| Keywords | koa, json |

## Links

- npm: https://www.npmjs.com/package/koa-json
- Repository: https://github.com/koajs/json
- Homepage: https://github.com/koajs/json#readme
- Issues: https://github.com/koajs/json/issues
- npm.io page: https://npm.io/package/koa-json

## Dependencies (2)

- [koa-is-json](https://npm.io/package/koa-is-json.md) 1
- [streaming-json-stringify](https://npm.io/package/streaming-json-stringify.md) 3

## 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

- 2.0.2 (latest) — 2016-04-28
- 1.1.3 — 2016-04-28
- 2.0.1 — 2016-04-28
- 1.1.2 — 2016-04-28
- 2.0.0 — 2016-03-27
- 1.1.1 — 2014-07-24
- 1.1.0 — 2014-05-28
- 1.0.1 — 2014-05-03
- 1.0.0 — 2014-05-03
- 0.0.2 — 2014-03-02
- 0.0.1 — 2014-02-01

## README

# koa-json

JSON pretty-printed response middleware. Also converts node object streams to binary.

## Installation

```
$ npm install koa-json
```

## Options

- `pretty` default to pretty response [true]
- `param` optional query-string param for pretty responses [none]
- `spaces` JSON spaces [2]

## Example

Always pretty by default:

```js
const json = require('koa-json')
const Koa = require('koa')
const app = new Koa()

app.use(json())

app.use((ctx) => {
  ctx.body = { foo: 'bar' }
})

// @request: GET /
//
// @response:
// {
//   "foo": "bar"
// }
```

Default to being disabled (useful in production), but togglable via the query-string parameter:

```js
const Koa = require('koa')
const app = new Koa()

app.use(json({ pretty: false, param: 'pretty' }))

app.use((ctx) => {
  ctx.body = { foo: 'bar' }
})

// @request: GET /
//
// @response:
// {"foo":"bar"}

// @request: GET /?pretty
//
// @response:
// {
//   "foo": "bar"
// }
```
 
# License 
 
[MIT](LICENSE)

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