{"id":13779426,"url":"https://github.com/koajs/json-filter","last_synced_at":"2025-07-21T11:36:33.787Z","repository":{"id":13017003,"uuid":"15696470","full_name":"koajs/json-filter","owner":"koajs","description":"Middleware allowing the client to filter the response to only what they need, reducing the amount of traffic over the wire.","archived":false,"fork":false,"pushed_at":"2018-04-10T08:17:26.000Z","size":12,"stargazers_count":92,"open_issues_count":2,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-14T13:08:40.275Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/koajs.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-01-07T06:05:06.000Z","updated_at":"2023-08-20T06:44:43.000Z","dependencies_parsed_at":"2022-09-03T11:20:37.218Z","dependency_job_id":null,"html_url":"https://github.com/koajs/json-filter","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fjson-filter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fjson-filter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fjson-filter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fjson-filter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koajs","download_url":"https://codeload.github.com/koajs/json-filter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219852408,"owners_count":16553393,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T18:01:05.068Z","updated_at":"2024-09-24T15:57:13.407Z","avatar_url":"https://github.com/koajs.png","language":"JavaScript","readme":"# koa-json-filter\n\nMiddleware allowing the client to filter the response to only what they need,\nreducing the amount of traffic over the wire using the `?filter=foo,bar,baz` querystring parameter.\n\nJSONSelect would also be great for this but I find it's a little too complicated for the average use-case,\nso this is just a simple key filter.\n\n## Installation\n\n```\n$ npm install @koa/json-filter\n```\n\nPlease 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`\n\n```\n$ npm install koa-json-filter@0.0.1\n```\n\n## Options\n\n* `name` querystring param defaulting to \"filter\"\n\n## Filtering customization\n\nYou may also set `ctx.filter` to an array of names to filter on,\nfor example by using a header field `X-Filter: name,email`.\n\n## Example\n\n### Object responses\n\nScript:\n\n```js\nconst Koa = require('koa');\nconst filter = require('@koa/json-filter');\n\nconst app = new Koa();\n\napp.use(filter());\n\napp.use(async ctx =\u003e {\n  ctx.body = {\n    name: 'tobi',\n    email: 'tobi@segment.io',\n    packages: 5,\n    friends: ['abby', 'loki', 'jane']\n  };\n});\n\napp.listen(3000);\nconsole.log('app listening on port 3000');\n```\n\nResponse:\n\n```\n$ GET /?filter=name\n{\n  \"name\": \"tobi\"\n}\n```\n\n### Array responses\n\nScript:\n\n```js\nconst Koa = require('koa');\nconst filter = require('@koa/json-filter');\n\nconst app = new Koa();\n\napp.use(filter());\n\napp.use(async ctx =\u003e {\n  ctx.body = [\n    {\n      name: 'tobi',\n      email: 'tobi@segment.io',\n      packages: 5,\n      friends: ['abby', 'loki', 'jane']\n    },\n    {\n      name: 'loki',\n      email: 'loki@segment.io',\n      packages: 2,\n      friends: ['loki', 'jane']\n    },\n    {\n      name: 'jane',\n      email: 'jane@segment.io',\n      packages: 2,\n      friends: []\n    },\n    {\n      name: 'ewald',\n      email: 'ewald@segment.io',\n      packages: 2,\n      friends: ['tobi']\n    }\n  ];\n});\n\napp.listen(3000);\nconsole.log('app listening on port 3000');\n```\n\nResponse:\n\n```\n$ GET /?filter=name,email\n[\n  {\n    \"name\": \"tobi\",\n    \"email\": \"tobi@segment.io\"\n  },\n  {\n    \"name\": \"loki\",\n    \"email\": \"loki@segment.io\"\n  },\n  {\n    \"name\": \"jane\",\n    \"email\": \"jane@segment.io\"\n  },\n  {\n    \"name\": \"ewald\",\n    \"email\": \"ewald@segment.io\"\n  }\n]\n```\n\n# License\n\nMIT\n","funding_links":[],"categories":["Middleware","仓库"],"sub_categories":["中间件"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoajs%2Fjson-filter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoajs%2Fjson-filter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoajs%2Fjson-filter/lists"}