koa-json
pretty (non-compressed) json response middleware
Last updated 4 years ago by coderhaoxin .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install koa-json 
SYNC missed versions from official npm registry.

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:

var json = require('koa-json');
var Koa = require('koa');
var app = new Koa();

app.use(json());

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

yields:

$ GET /

{
  "foo": "bar"
}

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

var Koa = require('koa');
var app = new Koa();

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

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

yields:

$ GET /

{"foo":"bar"}
$ GET /?pretty

{
  "foo": "bar"
}

License

MIT

Current Tags

  • 2.0.2                                ...           latest (4 years ago)
  • 2.0.2                                ...           next (4 years ago)

11 Versions

  • 2.0.2                                ...           4 years ago
  • 1.1.3                                ...           4 years ago
  • 2.0.1                                ...           4 years ago
  • 1.1.2                                ...           4 years ago
  • 2.0.0                                ...           5 years ago
  • 1.1.1                                ...           6 years ago
  • 1.1.0                                ...           6 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
  • 0.0.2                                ...           7 years ago
  • 0.0.1                                ...           7 years ago
Downloads
Today 50
This Week 50
This Month 8,012
Last Day 365
Last Week 2,238
Last Month 8,714
Dependencies (2)
Dev Dependencies (4)
Dependents (230)

Copyright 2014 - 2016 © taobao.org |