{"id":47156,"library":"better-ajv-errors","title":"better-ajv-errors","description":"A library that formats JSON Schema validation errors from Ajv into human-readable messages with codeframe highlighting and suggestions. Current version 2.0.3 supports Ajv versions 4.11.8 through 8, and requires Node >= 18.20.6. Ships TypeScript types and offers both CLI (console-friendly) and JS (structured) output formats. Unlike raw Ajv error objects, better-ajv-errors provides line/column references and 'did you mean?' suggestions.","status":"active","version":"2.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/atlassian/better-ajv-errors","tags":["javascript","json-schema","ajv","ajv-errors","typescript"],"install":[{"cmd":"npm install better-ajv-errors","lang":"bash","label":"npm"},{"cmd":"yarn add better-ajv-errors","lang":"bash","label":"yarn"},{"cmd":"pnpm add better-ajv-errors","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; used to produce the validation errors that better-ajv-errors formats","package":"ajv","optional":false}],"imports":[{"note":"In CommonJS, use require('better-ajv-errors').default to access the default export.","wrong":"const betterAjvErrors = require('better-ajv-errors');","symbol":"default (betterAjvErrors)","correct":"import betterAjvErrors from 'better-ajv-errors';"},{"note":"Direct require returns an object with a default property (ESM default export wrapped).","wrong":"const betterAjvErrors = require('better-ajv-errors');","symbol":"default (CommonJS)","correct":"const betterAjvErrors = require('better-ajv-errors').default;"},{"note":"ErrorOutput is the type for output when format: 'js' is used. Available since v2.","wrong":"","symbol":"ErrorOutput type (TypeScript)","correct":"import type { ErrorOutput } from 'better-ajv-errors';"}],"quickstart":{"code":"import Ajv from 'ajv';\nimport betterAjvErrors from 'better-ajv-errors';\n\nconst schema = {\n  type: 'object',\n  properties: {\n    name: { type: 'string' },\n    age: { type: 'integer', minimum: 0 },\n  },\n  required: ['name', 'age'],\n};\n\nconst data = { name: 42, age: -1 };\n\nconst ajv = new Ajv({ allErrors: true, verbose: true });\nconst validate = ajv.compile(schema);\nconst valid = validate(data);\n\nif (!valid) {\n  const output = betterAjvErrors(schema, data, validate.errors, { format: 'cli', indent: 2 });\n  console.log(output);\n}","lang":"javascript","description":"Demonstrates validating a payload with Ajv and formatting errors with better-ajv-errors in CLI mode."},"warnings":[{"fix":"new Ajv({ allErrors: true, verbose: true })","message":"Requires Ajv instance with allErrors: true and verbose: true to get detailed error information.","severity":"gotcha","affected_versions":"*"},{"fix":"Use .default or an import statement.","message":"CommonJS require: const betterAjvErrors = require('better-ajv-errors').default; not just require('better-ajv-errors').","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Set format option to 'js' if you need machine-readable output.","message":"Output format 'js' returns an array of objects with start/end positions; it is not the same as the default 'cli' string.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"search_vec":"'18.20.6':37 '2.0.3':27 '4.11.8':31 '8':33 'ajv':3,14,29,55,60,74,76 'ajv-error':75 'better':2,59 'better-ajv-error':1,58 'cli':44 'codefram':21 'consol':46 'console-friend':45 'current':25 'error':4,12,56,61,77 'format':8,52 'friend':47 'highlight':22 'human':17 'human-read':16 'javascript':70 'js':49 'json':9,72 'json-schema':71 'librari':6 'line/column':63 'mean':68 'messag':19 'node':36 'object':57 'offer':42 'output':51 'provid':62 'raw':54 'readabl':18 'refer':64 'requir':35 'schema':10,73 'ship':38 'structur':50 'suggest':24,69 'support':28 'type':40 'typescript':39,78 'unlik':53 'valid':11 'version':26,30","created_at":"2026-06-07T16:50:05.527459+00:00","updated_at":"2026-06-07T16:50:05.527459+00:00","problems":[{"fix":"Use require('better-ajv-errors').default","cause":"Using CommonJS require without .default on versions >=2","error":"TypeError: betterAjvErrors is not a function"},{"fix":"Call betterAjvErrors(schema, data, errors, { format: 'js' })","cause":"Passing options as second or third argument incorrectly","error":"Error: Unknown option \"format\""}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/atlassian/better-ajv-errors#readme","github":"https://github.com/atlassian/better-ajv-errors","docs":null,"changelog":null,"pypi":null,"npm":"better-ajv-errors","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}