# json **Repository Path**: mirrors_koajs/json ## Basic Information - **Project Name**: json - **Description**: pretty-printed JSON response middleware - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-09 - **Last Updated**: 2026-05-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## 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)