# @sidvind/better-ajv-errors

> JSON Schema validation for Human

Latest version **7.0.0** (published 2026-05-14) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @sidvind/better-ajv-errors
pnpm add @sidvind/better-ajv-errors
yarn add @sidvind/better-ajv-errors
bun add @sidvind/better-ajv-errors
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; high maintenance score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 7.0.0 |
| Published | 2026-05-14 |
| First published | 2019-12-08 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | ^22.12 \|\| >= 24.0 |
| Dependencies | 0 |
| Unpacked size | 467.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 2 |
| Author | Rifat Nabi |
| Maintainers | ext |
| Keywords | json-schema, ajv, ajv-errors |

## Links

- npm: https://www.npmjs.com/package/@sidvind/better-ajv-errors
- Repository: https://github.com/ext/better-ajv-errors
- Issues: https://github.com/ext/better-ajv-errors/issues
- npm.io page: https://npm.io/package/@sidvind/better-ajv-errors

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 7.0.0 (latest) — 2026-05-14
- 6.0.0 — 2026-05-12
- 5.0.0 — 2026-04-14
- 4.0.1 — 2025-11-21
- 4.0.0 — 2025-03-08
- 3.0.1 — 2024-09-09
- 3.0.0 — 2024-09-08
- 2.1.3 — 2023-12-10
- 2.1.2 — 2023-12-04
- 2.1.1 — 2023-12-03
- 2.1.0 — 2022-09-13
- 2.0.0 — 2022-05-07
- 1.1.1 — 2022-02-03
- 1.1.0 — 2022-02-03
- 1.0.2 — 2021-11-13
- … 9 more at https://npm.io/package/@sidvind/better-ajv-errors/versions

## README

<h1 align="center">
  <img width="570" src="media/logo.png" alt="better-ajv-errors">
  <br>
</h1>

> JSON Schema validation for Human 👨‍🎤

Main goal of this library is to provide relevant error messages like the following:

<p align="center">
  <img src="media/screenshot.svg">
</p>

## Fork

This fork removes the legacy build and thus drops dependencies such as `core-js`
and `@babel/runtime` which is not needed on modern installations.

- Node 12 and later supports the modern build and according to the release plan
  node 10 was EOL at 2021-04-30.
- Earlier versions is already EOL and not supported. Anyone using it should
  update instead.

The following PRs from upstream are merged:

- [PR-85: fix: enumeration in anyOf](https://github.com/atlassian/better-ajv-errors/pull/85)
- ~[PR-67: fix(typings): Correct TypeScript type definition](https://github.com/atlassian/better-ajv-errors/pull/67)~ (superseeded by upstream fix)
- ~[PR-70: Drop legacy build and dependecy on polyfills](https://github.com/atlassian/better-ajv-errors/pull/70)~ (dropped in favour of esbuild)

The following PRs has been merged upstream:

- [PR-84: feat: support `json` option to get accurate line/column listings](https://github.com/atlassian/better-ajv-errors/pull/84)
- [PR-92: feat: ajv 8 support](https://github.com/atlassian/better-ajv-errors/pull/92)

## Installation

```bash
$ npm i @sidvind/better-ajv-errors
```

Also make sure that you installed [ajv](https://www.npmjs.com/package/ajv) package to validate data against JSON schemas.

## Usage

First, you need to validate your payload with `ajv`. If it's invalid then you can pass `validate.errors` object into `better-ajv-errors`.

```js
import Ajv from 'ajv';
import betterAjvErrors from '@sidvind/better-ajv-errors';
// const Ajv = require('ajv');
// const betterAjvErrors = require('@sidvind/better-ajv-errors').default;
// Or
// const { default: betterAjvErrors } = require('@sidvid/better-ajv-errors');

// You need to pass `{ jsonPointers: true }` for older versions of ajv
const ajv = new Ajv();

// Load schema and data
const schema = ...;
const data = ...;

const validate = ajv.compile(schema);
const valid = validate(data);

if (!valid) {
  const output = betterAjvErrors(schema, data, validate.errors);
  console.log(output);
}
```

## API

### betterAjvErrors(schema, data, errors, [options])

Returns formatted validation error to **print** in `console`. See [`options.format`](#format) for further details.

#### schema

Type: `Object`

The JSON Schema you used for validation with `ajv`

#### data

Type: `Object`

The JSON payload you validate against using `ajv`

#### errors

Type: `Array`

Array of [ajv validation errors](https://github.com/epoberezkin/ajv#validation-errors)

#### options

Type: `Object`

##### format

Type: `string`  
Default: `cli`  
Values: `cli` `js`

Use default `cli` output format if you want to **print** beautiful validation errors like following:

<img width="620" src="media/screenshot.svg">

Or, use `js` if you are planning to use this with some API. Your output will look like following:

```javascript
[
  {
    start: { line: 6, column: 15, offset: 70 },
    end: { line: 6, column: 26, offset: 81 },
    error: "/content/0/type should be equal to one of the allowed values: panel, paragraph, ...",
    suggestion: "Did you mean paragraph?",
  },
];
```

##### indent

Type: `number` `null`  
Default: `null`

If you have an unindented JSON payload and you want the error output indented.

This option have no effect when using the `json` option.

##### json

Type: `string` `null`  
Default: `null`

Raw JSON payload used when formatting codeframe.
Gives accurate line and column listings.

##### colors

Type: `Object`  
Default: `{}` (no colors)

Color functions applied to CLI output.
Each key is optional - omitted keys default to a passthrough `(text) => text` function, producing plain text.

| Key        | Role                                        |
| ---------- | ------------------------------------------- |
| `error`    | Error message lines                         |
| `property` | Property/value names in code frames         |
| `bold`     | Error type labels (e.g. `ENUM`, `REQUIRED`) |

Using native `node:util`:

```js
import { styleText } from "node:util";
import betterAjvErrors from "@sidvind/better-ajv-errors";

const output = betterAjvErrors(schema, data, errors, {
  colors: {
    error: styleText.bind(undefined, "red"),
    property: styleText.bind(undefined, "magenta"),
    bold: styleText.bind(undefined, "bold"),
  },
});
```

Or a third-party dependency:

```js
import * as kleur from "kleur/colors";
import betterAjvErrors from "@sidvind/better-ajv-errors";

const output = betterAjvErrors(schema, data, errors, {
  colors: {
    error: kleur.red,
    property: kleur.magenta,
    bold: kleur.bold,
  },
});
```

---
_Source: https://npm.io/package/@sidvind/better-ajv-errors · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
