
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
@koa/json-filter
Advanced tools
Middleware allowing the client to filter the response to only what they need
Middleware allowing the client to filter the response to only what they need,
reducing the amount of traffic over the wire using the ?filter=foo,bar,baz querystring parameter.
JSONSelect would also be great for this but I find it's a little too complicated for the average use-case, so this is just a simple key filter.
$ npm install @koa/json-filter
Please note that if you're using an earlier version of koa 2 with function generator you need to install the older version 0.0.1
$ npm install koa-json-filter@0.0.1
name querystring param defaulting to "filter"You may also set ctx.filter to an array of names to filter on,
for example by using a header field X-Filter: name,email.
Script:
const Koa = require('koa');
const filter = require('@koa/json-filter');
const app = new Koa();
app.use(filter());
app.use(async ctx => {
ctx.body = {
name: 'tobi',
email: 'tobi@segment.io',
packages: 5,
friends: ['abby', 'loki', 'jane']
};
});
app.listen(3000);
console.log('app listening on port 3000');
Response:
$ GET /?filter=name
{
"name": "tobi"
}
Script:
const Koa = require('koa');
const filter = require('@koa/json-filter');
const app = new Koa();
app.use(filter());
app.use(async ctx => {
ctx.body = [
{
name: 'tobi',
email: 'tobi@segment.io',
packages: 5,
friends: ['abby', 'loki', 'jane']
},
{
name: 'loki',
email: 'loki@segment.io',
packages: 2,
friends: ['loki', 'jane']
},
{
name: 'jane',
email: 'jane@segment.io',
packages: 2,
friends: []
},
{
name: 'ewald',
email: 'ewald@segment.io',
packages: 2,
friends: ['tobi']
}
];
});
app.listen(3000);
console.log('app listening on port 3000');
Response:
$ GET /?filter=name,email
[
{
"name": "tobi",
"email": "tobi@segment.io"
},
{
"name": "loki",
"email": "loki@segment.io"
},
{
"name": "jane",
"email": "jane@segment.io"
},
{
"name": "ewald",
"email": "ewald@segment.io"
}
]
MIT
FAQs
Middleware allowing the client to filter the response to only what they need
We found that @koa/json-filter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 9 open source maintainers collaborating on the project.
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.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.