Package Exports
- koa-json
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (koa-json) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
koa-json
JSON pretty-printed response middleware. Also converts node object streams to binary.
Installation
$ npm install koa-jsonOptions
prettydefault to pretty response [true]paramoptional query-string param for pretty responses [none]spacesJSON 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