{"id":13798753,"url":"https://github.com/nemtsov/koa-json-mask","last_synced_at":"2026-03-11T04:31:27.177Z","repository":{"id":13351985,"uuid":"16039338","full_name":"nemtsov/koa-json-mask","owner":"nemtsov","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":"2020-10-30T21:28:45.000Z","size":9,"stargazers_count":23,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-07T05:03:29.159Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nemtsov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-01-19T03:31:36.000Z","updated_at":"2024-11-08T05:43:08.000Z","dependencies_parsed_at":"2022-07-21T16:34:27.514Z","dependency_job_id":null,"html_url":"https://github.com/nemtsov/koa-json-mask","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/nemtsov/koa-json-mask","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nemtsov%2Fkoa-json-mask","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nemtsov%2Fkoa-json-mask/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nemtsov%2Fkoa-json-mask/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nemtsov%2Fkoa-json-mask/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nemtsov","download_url":"https://codeload.github.com/nemtsov/koa-json-mask/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nemtsov%2Fkoa-json-mask/sbom","scorecard":{"id":679371,"data":{"date":"2025-08-11","repo":{"name":"github.com/nemtsov/koa-json-mask","commit":"a247637952d21347b207945c6ad14c3df04407dd"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.2,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Code-Review","score":1,"reason":"Found 1/10 approved changesets -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 2 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-21T22:35:54.089Z","repository_id":13351985,"created_at":"2025-08-21T22:35:54.089Z","updated_at":"2025-08-21T22:35:54.089Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30370797,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T21:41:54.280Z","status":"online","status_checked_at":"2026-03-11T02:00:07.027Z","response_time":84,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-04T00:00:52.258Z","updated_at":"2026-03-11T04:31:27.138Z","avatar_url":"https://github.com/nemtsov.png","language":"JavaScript","funding_links":[],"categories":["仓库"],"sub_categories":["中间件"],"readme":"# koa-json-mask\n\nMiddleware allowing the client to mask / filter the response to only what they need,\nreducing the amount of traffic over the wire using the `?fields=foo,bar,baz`\nquerystring parameter.\n\nIf you've used the Google APIs, provided a `?fields=` query-string to get a\n[Partial Response](https://developers.google.com/+/api/#partial-responses),\nand wanted to do the same for your own server, you can do so with this\nmiddleware.\n\nThe difference between `koa-json-filter` and `koa-json-mask` is that this middleware\nsupports filtering parts deep within objects. If you only need to be able to\nfilter top-level params of objects in the response use `filter`, and if you need\nmore power user `mask`.\n\n_Underneath, this middleware uses [json-mask](https://github.com/nemtsov/json-mask).\nUse it directly without this middleware if you need more flexibility._\n\n## Installation\n\n```\n$ npm install koa-json-mask\n```\n\nIn order to use this plugin with the previous version of Koa using generator functions, please use version `0.3.2`\n\n```\n$ npm install koa-json-mask@0.3.2\n```\n\n## Options\n\n* `name` querystring param name defaulting to \"fields\"\n\n## Example\n\n### Object responses\n\nScript:\n\n```js\nconst Koa = require('koa');\nconst mask = require('koa-json-mask');\n\nconst app = new Koa();\n\napp.use(mask());\n\napp.use(async ctx =\u003e {\n  ctx.body = {\n    name: 'tobi',\n    packages: 5,\n    friends: ['abby', 'loki', 'jane'],\n    location: {\n      id: '342',\n      name: 'London'\n    }\n  };\n});\n\napp.listen(3000);\nconsole.log('app listening on port 3000');\n```\n\nResponse:\n\n```\n$ GET /?fields=name,location/name\n{\n  \"name\": \"tobi\",\n  \"location\": {\n    \"name\": \"London\"\n  }\n}\n```\n\n### Array responses\n\nScript:\n\n```js\nconst Koa = require('koa');\nconst mask = require('koa-json-mask');\n\nconst app = new Koa();\n\napp.use(mask());\n\napp.use(async ctx =\u003e {\n  ctx.body = [\n    {\n      name: 'tobi',\n      packages: 5,\n      friends: ['abby', 'loki', 'jane'],\n      location: {\n        id: '342',\n        name: 'London'\n      }\n    },\n    {\n      name: 'loki',\n      packages: 2,\n      friends: ['loki', 'jane'],\n      location: {\n        id: '62',\n        name: 'New York'\n      }\n    }\n  ];\n});\n\napp.listen(3000);\nconsole.log('app listening on port 3000');\n```\n\nResponse:\n\n```\n$ GET /?fields=name,location/name\n[\n  {\n    \"name\": \"tobi\",\n    \"location\": {\n      \"name\": \"London\"\n    }\n  },\n  {\n    \"name\": \"loki\",\n    \"location\": {\n      \"name\": \"New York\"\n    }\n  }\n]\n```\n\n## Syntax\n\nThe syntax is loosely based on XPath:\n\n* `a,b,c` comma-separated list will select multiple fields\n* `a/b/c` path will select a field from its parent\n* `a(b,c)` sub-selection will select many fields from a parent\n* `a/*/c` the star `*` wildcard will select all items in a field\n\n## More examples\n\nFor more examples, take a look at the\n[examples section of the json-mask README](https://github.com/nemtsov/json-mask/#examples).\n\n# License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnemtsov%2Fkoa-json-mask","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnemtsov%2Fkoa-json-mask","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnemtsov%2Fkoa-json-mask/lists"}