koa-json
pretty (non-compressed) json response middleware
Last updated 10 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 (10 years ago)
  • 2.0.2                                ...           next (10 years ago)

11 Versions

  • 2.0.2                                ...           10 years ago
  • 1.1.3                                ...           10 years ago
  • 2.0.1                                ...           10 years ago
  • 1.1.2                                ...           10 years ago
  • 2.0.0                                ...           10 years ago
  • 1.1.1                                ...           12 years ago
  • 1.1.0                                ...           12 years ago
  • 1.0.1                                ...           12 years ago
  • 1.0.0                                ...           12 years ago
  • 0.0.2                                ...           12 years ago
  • 0.0.1                                ...           12 years ago
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 0
Dependencies (2)
Dev Dependencies (4)
Dependents (0)
None

Copyright 2013 - present © cnpmjs.org | Home |