Socket
Socket
Sign inDemoInstall

koa-json

Package Overview
Dependencies
11
Maintainers
9
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    koa-json

pretty (non-compressed) json response middleware


Version published
Weekly downloads
91K
decreased by-2.9%
Maintainers
9
Install size
206 kB
Created
Weekly downloads
 

Readme

Source

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

Keywords

FAQs

Last updated on 28 Apr 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc