{"id":13670699,"url":"https://github.com/nswbmw/another-json-schema","last_synced_at":"2025-09-15T03:22:05.485Z","repository":{"id":57180377,"uuid":"52535081","full_name":"nswbmw/another-json-schema","owner":"nswbmw","description":"Another JSON Schema validator, simple \u0026 flexible \u0026 intuitive.","archived":false,"fork":false,"pushed_at":"2024-11-11T06:04:01.000Z","size":60,"stargazers_count":47,"open_issues_count":2,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-25T04:55:11.581Z","etag":null,"topics":["json-schema","schema","validator"],"latest_commit_sha":null,"homepage":"","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/nswbmw.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-02-25T15:24:08.000Z","updated_at":"2025-02-11T15:48:30.000Z","dependencies_parsed_at":"2025-02-27T07:15:14.385Z","dependency_job_id":"bfe0299f-aa5d-4bb1-b68d-f2bb30dfdb4d","html_url":"https://github.com/nswbmw/another-json-schema","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nswbmw/another-json-schema","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nswbmw%2Fanother-json-schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nswbmw%2Fanother-json-schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nswbmw%2Fanother-json-schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nswbmw%2Fanother-json-schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nswbmw","download_url":"https://codeload.github.com/nswbmw/another-json-schema/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nswbmw%2Fanother-json-schema/sbom","scorecard":{"id":697455,"data":{"date":"2025-08-11","repo":{"name":"github.com/nswbmw/another-json-schema","commit":"6a8adb6b9f76f173def884650e9a0e752c5aa5be"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.6,"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":"Code-Review","score":0,"reason":"Found 2/27 approved changesets -- score normalized to 0","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":"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":"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":"License","score":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"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":"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 5 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-22T04:09:56.573Z","repository_id":57180377,"created_at":"2025-08-22T04:09:56.573Z","updated_at":"2025-08-22T04:09:56.573Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275198913,"owners_count":25422436,"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","status":"online","status_checked_at":"2025-09-15T02:00:09.272Z","response_time":75,"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":["json-schema","schema","validator"],"created_at":"2024-08-02T09:00:48.137Z","updated_at":"2025-09-15T03:22:05.449Z","avatar_url":"https://github.com/nswbmw.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"### another-json-schema\n\nAnother JSON Schema, simple \u0026 flexible \u0026 intuitive.\n\n[![NPM version][npm-image]][npm-url]\n[![Build status][travis-image]][travis-url]\n[![Dependency Status][david-image]][david-url]\n[![License][license-image]][license-url]\n[![Downloads][downloads-image]][downloads-url]\n\n### Install\n\n```sh\n$ npm i another-json-schema --save\n```\n\n### Usage\n\n### Simple\n\n```js\nconst AJS = require('another-json-schema')\n\nconst userSchema = AJS('userSchema', {\n  name: { type: 'string', required: true },\n  age: { type: 'number', gte: 18 },\n  gender: { type: 'string', enum: ['male', 'female'], default: 'male' },\n  email: { type: 'string', trim: true, isEmail: true }\n})\n\n// test `required`\nconsole.log(userSchema.validate({ age: 18 }))\n/*\n{ valid: false,\n  error:\n   { Error: ($.name: undefined) ✖ (required: true)\n     validator: 'required',\n     actual: undefined,\n     expected: { type: 'string', required: true },\n     path: '$.name',\n     schema: 'userSchema' },\n  result: { age: 18 } }\n*/\n\n// test `default`\nconst data = { name: 'nswbmw', age: 18 }\nconsole.log(userSchema.validate(data))\n/*\n{ valid: true,\n  error: null,\n  result: { name: 'nswbmw', age: 18, gender: 'male' } }\n*/\nconsole.log(data)\n// { name: 'nswbmw', age: 18, gender: 'male' }\n\n// test `enum`\nconsole.log(userSchema.validate({ name: 'nswbmw', age: 18, gender: 'lalala' }))\n/*\n{ valid: false,\n  error:\n   { Error: ($.gender: \"lalala\") ✖ (enum: male,female)\n     validator: 'enum',\n     actual: 'lalala',\n     expected: { type: 'string', enum: ['male', 'female'], default: 'male' },\n     path: '$.gender',\n     schema: 'userSchema' },\n  result: { name: 'nswbmw', age: 18, gender: 'lalala' } }\n*/\n\n// test `gte`\nconsole.log(userSchema.validate({ name: 'nswbmw', age: 17 }))\n/*\n{ valid: false,\n  error:\n   { Error: ($.age: 17) ✖ (gte: 18)\n     validator: 'gte',\n     actual: 17,\n     expected: { type: 'number', gte: 18 },\n     path: '$.age',\n     schema: 'userSchema' },\n  result: { name: 'nswbmw', age: 17 } }\n*/\n\n// test `isEmail`\nconsole.log(userSchema.validate({ name: 'nswbmw', email: 'myEmail' }))\n/*\n{ valid: false,\n  error:\n   { Error: ($.email: \"myEmail\") ✖ (isEmail: true)\n     validator: 'isEmail',\n     path: '$.email',\n     actual: 'myEmail',\n     expected: { type: 'string', trim: true, isEmail: true },\n     schema: 'userSchema' },\n  result: { name: 'nswbmw', email: 'myEmail', gender: 'male' } }\n*/\n```\n\n### Nested\n\n```js\nconst AJS = require('another-json-schema')\n\nconst userSchema = AJS('userSchema', {\n  _id: { type: 'string', pattern: /^[0-9a-z]{24}$/, required: true },\n  name: { type: 'string' },\n  age: { type: 'number', gte: 18 },\n  gender: { type: 'string', enum: ['male', 'female'] }\n})\n\nconst commentSchema = AJS('commentSchema', {\n  _id: { type: 'string', pattern: /^[0-9a-z]{24}$/, required: true },\n  user: userSchema,\n  content: { type: 'string' }\n})\n\nconst postSchema = AJS('postSchema', {\n  _id: { type: 'string', pattern: /^[0-9a-z]{24}$/, required: true },\n  author: userSchema,\n  content: { type: 'string' },\n  comments: [commentSchema]\n})\n\nconst post = {\n  _id: 'post11111111111111111111',\n  author: {\n    _id: 'user11111111111111111111',\n    name: 'nswbmw',\n    age: 100,\n    gender: 'male',\n    pet: 'cat'\n  },\n  content: 'lalala',\n  comments: [{\n    _id: 'comment11111111111111111',\n    user: {\n      _id: 'wrong_id',\n      name: 'user1',\n      age: 100,\n      gender: 'male'\n    },\n    content: 'sofa'\n  }]\n}\n\nconsole.log(postSchema.validate(post))\n/*\n{ valid: false,\n  error:\n   { [Error: ($.comments[].user._id: \"wrong_id\") ✖ (pattern: /^[0-9a-z]{24}$/)]\n     validator: 'pattern',\n     actual: 'wrong_id',\n     expected: { type: 'string', pattern: /^[0-9a-z]{24}$/, required: true },\n     path: '$.comments[].user._id',\n     schema: 'userSchema' },\n  result:\n   { _id: 'post11111111111111111111',\n     author:\n      { _id: 'user11111111111111111111',\n        name: 'nswbmw',\n        age: 100,\n        gender: 'male' },\n     content: 'lalala',\n     comments: [ [Object] ] } }\n*/\n```\n\n### Custom Error Message\n\n```js\nconst AJS = require('another-json-schema')\n\nconst userSchema = AJS('userSchema', {\n  name: { type: 'string', required: true },\n  age: {\n    type: 'number',\n    gte: 18,\n    _customErrorMsg: {\n      gte: '您未满 18 岁'\n    }\n  }\n})\n\n// test `_customErrorMsg`\nconsole.log(userSchema.validate({\n  name: 'nswbmw',\n  age: 17\n}))\n/*\n{ valid: false,\n  error:\n   { Error: 您未满 18 岁\n     validator: 'gte',\n     path: '$.age',\n     actual: 17,\n     expected: { type: 'number', gte: 18, _customErrorMsg: [Object] },\n     schema: 'userSchema' },\n  result: { name: 'nswbmw', age: 17 } }\n*/\n```\n\n\n### Register validator\n\n```js\nconst AJS = require('another-json-schema')\n\nAJS.register('adult', function (actual, expected, key, parent) {\n  return expected ? (actual \u003e 18) : (actual \u003c= 18)\n})\nconst adultSchema = AJS('adultSchema', { type: 'number', adult: true })\n\nconsole.log(adultSchema.validate(19))\n// { valid: true, error: null, result: 19 }\nconsole.log(adultSchema.validate(17))\n/*\n{ valid: false,\n  error:\n   { Error: ($: 17) ✖ (adult: true)\n     validator: 'adult',\n     actual: 17,\n     expected: { type: 'number', adult: true },\n     path: '$',\n     schema: 'adultSchema' },\n  result: 17 }\n*/\n```\n\n### Custom type validate function\n\nCustom ObjectId validator, check whether ObjectId then wrap `_id` string to ObjectId.\n\n```js\nconst AJS = require('another-json-schema')\nconst validator = require('validator')\nconst toObjectId = require('mongodb').ObjectId\n\nfunction ObjectId(actual, key, parent) {\n  if (!actual || !validator.isMongoId(actual.toString())) {\n    return false\n  }\n  parent[key] = toObjectId(actual)\n  return true\n}\n\nconst postSchema = AJS('postSchema', {\n  commentIds: [{ type: ObjectId }]\n})\n\nconst user = {\n  commentIds: [\n    '111111111111111111111111',\n    '222222222222222222222222'\n  ]\n}\n\nconsole.log(postSchema.validate(user))\n/*\n{ valid: true,\n  error: null,\n  result: { commentIds: [ 111111111111111111111111, 222222222222222222222222 ] } }\n*/\n\n//validate specific field\nconsole.log(postSchema._children.commentIds.validate('lalala'))\n/*\n{ valid: false,\n  error:\n   { Error: ($.commentIds[]: \"lalala\") ✖ (type: ObjectId)\n     validator: 'type',\n     path: '$.commentIds[]',\n     actual: 'lalala',\n     expected: [ [Object] ],\n     schema: 'postSchema' },\n  result: 'lalala' }\n*/\n```\n\n### Internal type validator\n\n- 'string'\n- 'number'\n- 'boolean'\n- AJS.Types.ObjectId\n- AJS.Types.String\n- AJS.Types.Number\n- AJS.Types.Integer\n- AJS.Types.Double\n- AJS.Types.Date\n- AJS.Types.Buffer\n- AJS.Types.Boolean\n- AJS.Types.Mixed\n\n**What's difference between `number` and `AJS.Types.Number` ?**\n`number` only check type, `AJS.Types.Number` will try to convert value to a number, if failed then throw error.\n\n```js\nconst AJS = require('/Users/nswbmw/work/GitHub/Node.js/another-json-schema')\n\nconst postSchema = AJS('postSchema', {\n  commentIds: [{ type: AJS.Types.ObjectId }]\n})\n\nconst user = {\n  commentIds: [\n    '111111111111111111111111',\n    '222222222222222222222222'\n  ]\n}\n\nconsole.log(postSchema.validate(user))\n/*\n{ valid: true,\n  error: null,\n  result: { commentIds: [ 111111111111111111111111, 222222222222222222222222 ] } }\n*/\n\n//validate specific field\nconsole.log(postSchema._children.commentIds.validate('lalala'))\n/*\n{ valid: false,\n  error:\n   { Error: ($.commentIds[]: \"lalala\") ✖ (type: ObjectId)\n     validator: 'type',\n     path: '$.commentIds[]',\n     actual: 'lalala',\n     expected: [ [Object] ],\n     schema: 'postSchema' },\n  result: 'lalala' }\n*/\n```\n\n#### Ignore validator\n\n```js\nconst AJS = require('another-json-schema')\n\nconst userSchema = AJS('userSchema', {\n  _id: { type: 'number', range: [1, 100] }\n})\n\nconst user = {\n  _id: 0\n}\n\nconsole.log(userSchema.validate(user))\n/*\n{ valid: false,\n  error:\n   { Error: ($._id: 0) ✖ (range: 1,100)\n     validator: 'range',\n     actual: 0,\n     expected: { type: 'number', range: [Array] },\n     path: '$._id',\n     schema: 'userSchema' },\n  result: { _id: 0 } }\n*/\nconsole.log(userSchema.validate(user, { range: false }))\n// { valid: true, error: null, result: { _id: 0 } }\n```\n\n**NB**: `type` validator cannot ignore by passing `false`.\n\n### API\n\n#### AJS([name], schema)\n\nConstructor.\n\n#### AJS.register(name, fn)\n\nRegister a validator. eg:\n\n```js\nAJS.register('adult', function (actual, expected, key, parent) {\n  return expected ? (actual \u003e 18) : (actual \u003c= 18)\n})\n```\n\n#### ajs.compile([name], schema)\n\nCompile a schema. The following two ways are the same:\n\n```js\nconst userSchema = AJS('userSchema', {\n  _id: { type: 'string', pattern: /^[0-9a-z]{24}$/ },\n  name: { type: 'string' },\n  age: { type: 'number', gte: 18 },\n  gender: { type: 'string', enum: ['male', 'female'] }\n})\n```\n\n```js\nconst newSchema = new AJS()\nconst userSchema = newSchema.compile('userSchema', {\n  _id: { type: 'string', pattern: /^[0-9a-z]{24}$/ },\n  name: { type: 'string' },\n  age: { type: 'number', gte: 18 },\n  gender: { type: 'string', enum: ['male', 'female'] }\n})\n```\n\n#### compiledSchema.validate(data, [opts])\n\nUse the compiled validator to validate an object. it will modify the original object and return it:\n\n- valid: {Boolean} wether a valid object\n- error: {Error|null}\n  - message: error message, eg: `($.comments[].user._id: \"wrong_id\") ✖ (pattern: /^[0-9a-z]{24}$/)`\n  - validator: validator name, eg: `pattern`,\n  - actual: actual value, eg: `wrong_id`,\n  - expected: expected schema, eg: `{ type: 'string', pattern: /^[0-9a-z]{24}$/ }`,\n  - path: path in object, eg: `$.comments[].user._id`,\n  - schema: schema name, eg: `userSchema`\n  - originError: original error thrown from validator\n- result: {Any}\n\nopts:\n\n- additionalProperties: {Boolean} if true, retain the original field. default `false`\n- ignoreNodeType: {Boolean} if true, ignore check node type, like: `[]`. default: `false`\n- gt, gte, lt, lte ...: {Boolean} if false, will not execute this validator.\n\n### Built-in validators\n\n- type\n- eq|equal\n- gt\n- gte\n- lt\n- lte\n- range\n- enum\n- pattern\n- default\n- required\n- all [validator](https://www.npmjs.com/package/validator)'s `isXxx` validators, eg: isEmail. `type` validator must be `string` or `AJS.Types.String`.\n\n### More examples\n\nsee [test](./test).\n\n### Test\n\n```sh\n$ npm test (coverage 100%)\n```\n\n### License\n\nMIT\n\n[npm-image]: https://img.shields.io/npm/v/another-json-schema.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/another-json-schema\n[travis-image]: https://img.shields.io/travis/nswbmw/another-json-schema.svg?style=flat-square\n[travis-url]: https://travis-ci.org/nswbmw/another-json-schema\n[david-image]: http://img.shields.io/david/nswbmw/another-json-schema.svg?style=flat-square\n[david-url]: https://david-dm.org/nswbmw/another-json-schema\n[license-image]: http://img.shields.io/npm/l/another-json-schema.svg?style=flat-square\n[license-url]: LICENSE\n[downloads-image]: http://img.shields.io/npm/dm/another-json-schema.svg?style=flat-square\n[downloads-url]: https://npmjs.org/package/another-json-schema\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnswbmw%2Fanother-json-schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnswbmw%2Fanother-json-schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnswbmw%2Fanother-json-schema/lists"}