{"id":13523683,"url":"https://github.com/atlassian/better-ajv-errors","last_synced_at":"2025-05-14T18:03:53.192Z","repository":{"id":40435550,"uuid":"109218345","full_name":"atlassian/better-ajv-errors","owner":"atlassian","description":"JSON Schema validation for Human 👨‍🎤","archived":false,"fork":false,"pushed_at":"2025-04-29T02:23:14.000Z","size":1493,"stargazers_count":238,"open_issues_count":48,"forks_count":46,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-29T03:37:13.225Z","etag":null,"topics":["ajv","json-schema"],"latest_commit_sha":null,"homepage":"https://atlassian.github.io/better-ajv-errors/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/atlassian.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2017-11-02T04:39:31.000Z","updated_at":"2025-04-22T06:27:55.000Z","dependencies_parsed_at":"2023-02-08T06:16:08.239Z","dependency_job_id":"b034f623-ab68-42f4-b260-03c3e65e3b09","html_url":"https://github.com/atlassian/better-ajv-errors","commit_stats":{"total_commits":153,"total_committers":19,"mean_commits":8.052631578947368,"dds":0.4117647058823529,"last_synced_commit":"70356a517e452d774dbf5d480e1e8bf1d5d07388"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atlassian%2Fbetter-ajv-errors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atlassian%2Fbetter-ajv-errors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atlassian%2Fbetter-ajv-errors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atlassian%2Fbetter-ajv-errors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/atlassian","download_url":"https://codeload.github.com/atlassian/better-ajv-errors/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253356272,"owners_count":21895672,"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":["ajv","json-schema"],"created_at":"2024-08-01T06:01:02.635Z","updated_at":"2025-05-14T18:03:48.178Z","avatar_url":"https://github.com/atlassian.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","others"],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n  \u003cimg width=\"570\" src=\"media/logo.png\" alt=\"better-ajv-errors\"\u003e\n  \u003cbr\u003e\n\u003c/h1\u003e\n\n\u003e JSON Schema validation for Human 👨‍🎤\n\nMain goal of this library is to provide relevant error messages like the following:\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"media/screenshot.svg\"\u003e\n\u003c/p\u003e\n\n## Installation\n\n```bash\n$ npm i better-ajv-errors\n$ # Or\n$ yarn add better-ajv-errors\n```\n\nAlso make sure that you installed [ajv](https://www.npmjs.com/package/ajv) package to validate data against JSON schemas.\n\n## Usage\n\nFirst, you need to validate your payload with `ajv`. If it's invalid then you can pass `validate.errors` object into `better-ajv-errors`.\n\n```js\nimport Ajv from 'ajv';\nimport betterAjvErrors from 'better-ajv-errors';\n// const Ajv = require('ajv');\n// const betterAjvErrors = require('better-ajv-errors').default;\n// Or\n// const { default: betterAjvErrors } = require('better-ajv-errors');\n\n// You need to pass `{ jsonPointers: true }` for older versions of ajv\nconst ajv = new Ajv();\n\n// Load schema and data\nconst schema = ...;\nconst data = ...;\n\nconst validate = ajv.compile(schema);\nconst valid = validate(data);\n\nif (!valid) {\n  const output = betterAjvErrors(schema, data, validate.errors);\n  console.log(output);\n}\n```\n\n## API\n\n### betterAjvErrors(schema, data, errors, [options])\n\nReturns formatted validation error to **print** in `console`. See [`options.format`](#format) for further details.\n\n#### schema\n\nType: `Object`\n\nThe JSON Schema you used for validation with `ajv`\n\n#### data\n\nType: `Object`\n\nThe JSON payload you validate against using `ajv`\n\n#### errors\n\nType: `Array`\n\nArray of [ajv validation errors](https://github.com/epoberezkin/ajv#validation-errors)\n\n#### options\n\nType: `Object`\n\n##### format\n\nType: `string`  \nDefault: `cli`  \nValues: `cli` `js`\n\nUse default `cli` output format if you want to **print** beautiful validation errors like following:\n\n\u003cimg width=\"620\" src=\"media/screenshot.svg\"\u003e\n\nOr, use `js` if you are planning to use this with some API. Your output will look like following:\n\n```javascript\n[\n  {\n    start: { line: 6, column: 15, offset: 70 },\n    end: { line: 6, column: 26, offset: 81 },\n    error:\n      '/content/0/type should be equal to one of the allowed values: panel, paragraph, ...',\n    suggestion: 'Did you mean paragraph?',\n  },\n];\n```\n\n##### indent\n\nType: `number` `null`  \nDefault: `null`\n\nIf you have an unindented JSON payload and you want the error output indented.\n\nThis option have no effect when using the `json` option.\n\n##### json\n\nType: `string` `null`  \nDefault: `null`\n\nRaw JSON payload used when formatting codeframe.\nGives accurate line and column listings.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatlassian%2Fbetter-ajv-errors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatlassian%2Fbetter-ajv-errors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatlassian%2Fbetter-ajv-errors/lists"}