Gathering detailed insights and metrics for better-ajv-errors
Gathering detailed insights and metrics for better-ajv-errors
Gathering detailed insights and metrics for better-ajv-errors
Gathering detailed insights and metrics for better-ajv-errors
JSON Schema validation for Human 👨🎤
npm install better-ajv-errors
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
235 Stars
157 Commits
45 Forks
7 Watching
14 Branches
76 Contributors
Updated on 13 Nov 2024
Minified
Minified + Gzipped
JavaScript (98.92%)
TypeScript (0.76%)
Shell (0.32%)
Cumulative downloads
Total Downloads
Last day
-5.4%
59,213
Compared to previous day
Last week
0.9%
345,109
Compared to previous week
Last month
2.2%
1,479,022
Compared to previous month
Last year
4.5%
16,001,612
Compared to previous year
1
JSON Schema validation for Human 👨🎤
Main goal of this library is to provide relevant error messages like the following:
1$ npm i better-ajv-errors 2$ # Or 3$ yarn add better-ajv-errors
Also make sure that you installed ajv package to validate data against JSON schemas.
First, you need to validate your payload with ajv
. If it's invalid then you can pass validate.errors
object into better-ajv-errors
.
1import Ajv from 'ajv'; 2import betterAjvErrors from 'better-ajv-errors'; 3// const Ajv = require('ajv'); 4// const betterAjvErrors = require('better-ajv-errors').default; 5// Or 6// const { default: betterAjvErrors } = require('better-ajv-errors'); 7 8// You need to pass `{ jsonPointers: true }` for older versions of ajv 9const ajv = new Ajv(); 10 11// Load schema and data 12const schema = ...; 13const data = ...; 14 15const validate = ajv.compile(schema); 16const valid = validate(data); 17 18if (!valid) { 19 const output = betterAjvErrors(schema, data, validate.errors); 20 console.log(output); 21}
Returns formatted validation error to print in console
. See options.format
for further details.
Type: Object
The JSON Schema you used for validation with ajv
Type: Object
The JSON payload you validate against using ajv
Type: Array
Array of ajv validation errors
Type: Object
Type: string
Default: cli
Values: cli
js
Use default cli
output format if you want to print beautiful validation errors like following:
Or, use js
if you are planning to use this with some API. Your output will look like following:
1[ 2 { 3 start: { line: 6, column: 15, offset: 70 }, 4 end: { line: 6, column: 26, offset: 81 }, 5 error: 6 '/content/0/type should be equal to one of the allowed values: panel, paragraph, ...', 7 suggestion: 'Did you mean paragraph?', 8 }, 9];
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.
Type: string
null
Default: null
Raw JSON payload used when formatting codeframe. Gives accurate line and column listings.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
SAST tool detected but not run on all commits
Details
Reason
Found 2/12 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dangerous workflow patterns detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
15 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More