Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ajv-errors

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ajv-errors

Custom error messages in JSON-Schema for Ajv validator

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.4M
decreased by-30.78%
Maintainers
1
Weekly downloads
 
Created

What is ajv-errors?

The ajv-errors package allows you to customize error messages in JSON Schema validation using the Ajv validator. It provides a way to enhance the default error messages that Ajv produces, making them more informative and user-friendly. This can be particularly useful in applications where precise and clear validation errors are necessary, such as form validation in web applications.

What are ajv-errors's main functionalities?

Custom error messages for specific validation keywords

This feature allows you to specify custom error messages for specific validation keywords, such as 'required', 'type', etc. In the provided code sample, a custom error message is defined for when the 'name' field is missing.

{ "type": "object", "properties": { "name": { "type": "string" } }, "required": ["name"], "errorMessage": { "required": { "name": "Name is required." } } }

Conditional error messages

This feature enables conditional error messages based on the validation outcome. In the example, a custom error message is set for the 'passwordConfirm' field to ensure it matches the 'password' field.

{ "type": "object", "properties": { "password": { "type": "string" }, "passwordConfirm": { "type": "string", "const": { "$data": "1/password" } } }, "errorMessage": { "properties": { "passwordConfirm": "Passwords must match." } } }

Top-level error messages

Allows setting a top-level error message for the entire schema. This is useful for providing a general error message instead of or in addition to specific field errors. The example sets a general error message regarding the 'age' field.

{ "type": "object", "properties": { "age": { "type": "number" } }, "required": ["age"], "errorMessage": "An age is required and must be a number." }

Other packages similar to ajv-errors

Keywords

FAQs

Package last updated on 27 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc