Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
awesome-ajv-errors
Advanced tools
awesome-ajv-errors pretty-prints ajv errors
It has a gorgeous human-understandable output, predicts human errors and suggests fixes.
Suggest similar properties
schema.json
{
"title": "Second-level two similar properties",
"type": "object",
"properties": {
"foo": {
"type": "object",
"properties": {
"bar": {},
"bak": {}
},
"additionalProperties": false
}
}
}
data.json
{
"foo": {
"bar": "42",
"baz": "33"
}
}
Suggests multiple valid property names
schema.json
{
"title": "Second-level three similar properties",
"type": "object",
"properties": {
"foo": {
"type": "object",
"properties": {
"bar": {},
"bak": {},
"bam": {}
},
"additionalProperties": false
}
}
}
data.json
{
"foo": {
"bar": "42",
"baz": "33"
}
}
Suggests the valid value type when mistaken
schema.json
{
"title": "One option (number to string)",
"type": "object",
"properties": {
"foo": {
"anyOf": [
{
"type": "string"
}
]
}
}
}
data.json
{
"foo": 42
}
Suggests the valid value type when mistaken
schema.json
{
"title": "One option (string to number)",
"type": "object",
"properties": {
"foo": {
"anyOf": [
{
"type": "number"
}
]
}
}
}
data.json
{
"foo": "42"
}
When the type mismatch, and one type is much "better" than the rest (as in probably the right solution), it will be suggested for conversion
schema.json
{
"title": "Two options",
"type": "object",
"properties": {
"foo": {
"anyOf": [
{
"type": "string"
},
{
"type": "boolean"
}
]
}
}
}
data.json
{
"foo": 42
}
schema.json
{
"title": "Three options",
"type": "object",
"properties": {
"foo": {
"anyOf": [
{
"type": "string"
},
{
"type": "boolean"
},
{
"type": "null"
}
]
}
}
}
data.json
{
"foo": 42
}
schema.json
{
"title": "2 too few",
"type": "object",
"properties": {
"foo": {
"type": "array",
"minItems": 3
}
}
}
data.json
{
"foo": [
1
]
}
schema.json
{
"title": "Less than or equal to",
"type": "object",
"properties": {
"foo": {
"type": "number",
"maximum": 17
}
}
}
data.json
{
"foo": 42
}
schema.json
{
"title": "One value of same type",
"type": "object",
"properties": {
"foo": {
"enum": [
41
]
}
}
}
data.json
{
"foo": 42
}
schema.json
{
"title": "Two options (one of different type)",
"type": "object",
"properties": {
"foo": {
"enum": [
41,
"42"
]
}
}
}
data.json
{
"foo": 42
}
schema.json
{
"title": "Four options (one of different type)",
"type": "object",
"properties": {
"foo": {
"enum": [
"falso",
"other",
"False",
false
]
}
}
}
data.json
{
"foo": "false"
}
schema.json
{
"title": "time invalid",
"type": "object",
"properties": {
"foo": {
"type": "string",
"format": "time"
}
}
}
data.json
{
"foo": "11:22:334"
}
schema.json
{
"title": "email invalid",
"type": "object",
"properties": {
"foo": {
"type": "string",
"format": "email"
}
}
}
data.json
{
"foo": "quite@invalid@email.com"
}
schema.json
{
"title": "if-then on first-level object",
"properties": {
"foo": {
"if": {
"properties": {
"firstName": {
"const": true
}
}
},
"then": {
"required": [
"lastName"
]
}
}
}
}
data.json
{
"foo": {
"firstName": true
}
}
schema.json
{
"title": "Multiple of",
"type": "object",
"properties": {
"foo": {
"type": "number",
"multipleOf": 4
}
}
}
data.json
{
"foo": 17
}
schema.json
{
"title": "Root-level required",
"type": "object",
"properties": {
"foo": {}
},
"required": [
"foo"
]
}
data.json
{
"bar": 42
}
Import the ajv
package, and prettify
from awesome-ajv-errors
:
import * as Ajv from 'ajv'
import { prettify } from 'awesome-ajv-errors'
Create an ajv instance and validate objects:
const ajv = new Ajv( { allErrors: true } ); // allErrors is optional
let data, schema; // Get the JSON schema and the JSON data from somewhere
const validate = ajv.compile( schema );
validate( data );
Now, the validation error is stored on the validate
function. Use prettify
to pretty-print the errors, and provide the data so that awesome-ajv-errors can suggest fixes:
console.log( prettify( validate, { data } ) );
FAQs
Prettified AJV errors
The npm package awesome-ajv-errors receives a total of 34,245 weekly downloads. As such, awesome-ajv-errors popularity was classified as popular.
We found that awesome-ajv-errors demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.