# ajv-error-messages

> Normalise AJV error messages

Latest version **2.1.0** (published 2022-02-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install ajv-error-messages
pnpm add ajv-error-messages
yarn add ajv-error-messages
bun add ajv-error-messages
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2022-02-14 |
| First published | 2016-08-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Anders Rasmussen |
| Maintainers | divinegod |
| Keywords | ajv, jsonschema, schema |

## Links

- npm: https://www.npmjs.com/package/ajv-error-messages
- Repository: https://github.com/DivineGod/ajv-error-messages
- Homepage: https://github.com/DivineGod/ajv-error-messages#readme
- Issues: https://github.com/DivineGod/ajv-error-messages/issues
- npm.io page: https://npm.io/package/ajv-error-messages

## 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

- 2.1.0 (latest) — 2022-02-14
- 2.0.0 — 2022-02-13
- 1.0.3 — 2021-02-23
- 1.0.2 — 2018-08-06
- 1.0.1 — 2018-08-06
- 1.0.0 — 2016-08-30

## README

# ajv-error-messages

Normalise errors from ajv to a simpler format.

Takes ajv errors and returns a simpler object. Inspired by https://github.com/MauriceButler/jayschema-error-messages

# AJV Version

v2 of `ajv-error-messages` has been upgraded to work with v8 of `ajv` 

## Usage

```javascript
var normalise = require('ajv-error-messages');
var SchemaValidator = require('ajv');
var schemaValidator = SchemaValidator({ allErrors: true });

var schema = {
    description: 'test schema',
    type: 'object',
    additionalProperties: false,
    required: ['foo'],
    properties: {
        foo: {
            type: 'string',
        },
    },
};
var invalidData = {
    foo: 2,
};

var validator = schemaValidator.compile(schema);

function validatingData(data) {

    var valid = validator(data);
    var normalisedErrors;
    if (!valid) {
        var ajvErrors = validator.errors
        normalisedErrors = normalise(ajvErrors);
    }

    return valid || normalisedErrors;
}

console.log(JSON.stringify(validatingData(invalidData)));
```

results in

```
{
    fields: {
        'foo': ['Must be string']
    }
}
```

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