{"id":47243,"library":"chai-json-schema-ajv","title":"chai-json-schema-ajv","description":"Chai plugin for JSON Schema validation using Ajv. Current stable version is 5.2.4, released in mid-2020 with support for Ajv >=4 and JSON Schema drafts 4, 6, and 7. It provides fluent chai assertions (jsonSchema, validJsonSchema) for both data validation and schema validation. Unlike chai-json-schema (which uses tv4), this plugin uses Ajv for better performance and compliance. The library exposes a .create() method for custom Ajv options. Maintenance mode since v5, with no active development.","status":"maintenance","version":"5.2.4","language":"javascript","source_language":"en","source_url":"https://github.com/up9cloud/chai-json-schema-ajv","tags":["javascript","chai","chai-plugin","json-schema","assert","test","schema","ajv"],"install":[{"cmd":"npm install chai-json-schema-ajv","lang":"bash","label":"npm"},{"cmd":"yarn add chai-json-schema-ajv","lang":"bash","label":"yarn"},{"cmd":"pnpm add chai-json-schema-ajv","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency required for JSON Schema validation; must be installed separately","package":"ajv","optional":true}],"imports":[{"note":"CJS require works but for ESM projects use default import. Since v5, package has both CJS and ESM exports.","wrong":"const chaiJsonSchema = require('chai-json-schema-ajv');","symbol":"default","correct":"import chaiJsonSchema from 'chai-json-schema-ajv';"},{"note":"Named export for creating a chai plugin with custom Ajv options.","wrong":"const { create } = require('chai-json-schema-ajv');","symbol":"create","correct":"import { create } from 'chai-json-schema-ajv';"},{"note":"jsonSchema is a chai property, not a direct import. It is added to chai assertions after using the plugin.","wrong":"import { jsonSchema } from 'chai-json-schema-ajv';","symbol":"jsonSchema","correct":"const chai = require('chai'); chai.use(require('chai-json-schema-ajv')); expect(data).to.be.jsonSchema(schema);"},{"note":"validJsonSchema is a property, not a method. It does not take arguments.","wrong":"expect(schema).to.be.validJsonSchema(schema);","symbol":"validJsonSchema","correct":"expect(schema).to.be.validJsonSchema;"}],"quickstart":{"code":"const chai = require('chai');\nconst chaiJsonSchema = require('chai-json-schema-ajv');\nchai.use(chaiJsonSchema);\nconst expect = chai.expect;\n\nconst data = { name: 'apple', color: ['red'], value: 10 };\nconst schema = {\n  type: 'object',\n  required: ['name', 'color', 'value'],\n  properties: {\n    name: { type: 'string', minLength: 3 },\n    color: { type: 'array', minItems: 1, items: { type: 'string' } },\n    value: { type: 'integer', minimum: 5 }\n  }\n};\n\nexpect(data).to.be.jsonSchema(schema, 'data passes schema');\nexpect({}).to.not.be.jsonSchema(schema, 'empty fails');\n\n// Validate schema itself\nexpect(schema).to.be.validJsonSchema;\nexpect({ type: 'invalid' }).to.not.be.validJsonSchema;","lang":"javascript","description":"Demonstrates basic usage of jsonSchema and validJsonSchema chai assertions for data and schema validation."},"warnings":[{"fix":"Update test assertions to match new default error messages from Ajv.errorsText().","message":"v5 changed error message format compared to v4; assertions may fail if tests rely on exact error text.","severity":"breaking","affected_versions":">=5.0.0 <6.0.0"},{"fix":"Install Ajv v7: npm install ajv@7 --save-dev","message":"Ajv v8 is not supported; plugin only supports Ajv v4 to v7 (but documented as >=4). Use Ajv v7 for latest draft-07 support.","severity":"deprecated","affected_versions":">=5.0.0"},{"fix":"Ensure Ajv is installed: npm install ajv --save-dev","message":"The plugin does not automatically install Ajv; it must be added as a direct dependency. Missing Ajv leads to cryptic runtime errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always provide an options object, even if empty: chai.use(require('chai-json-schema-ajv').create({}))","message":"Using .create() without arguments will fail because it expects at least an empty object; otherwise Ajv constructor is not called correctly.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use it without parentheses: expect(schema).to.be.validJsonSchema;","message":"validJsonSchema is a property flag, not a chainable method. Attempting to call it as a function (e.g., .validJsonSchema(schema)) will fail silently or throw.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'-2020':22 '4':27,32 '5.2.4':18 '6':33 '7':35 'activ':83 'ajv':5,13,26,61,75,96 'assert':40,93 'better':63 'chai':2,6,39,52,86,88 'chai-json-schema':51 'chai-json-schema-ajv':1 'chai-plugin':87 'complianc':66 'creat':71 'current':14 'custom':74 'data':45 'develop':84 'draft':31 'expos':69 'fluent':38 'javascript':85 'json':3,9,29,53,91 'json-schema':90 'jsonschema':41 'librari':68 'mainten':77 'method':72 'mid':21 'mode':78 'option':76 'perform':64 'plugin':7,59,89 'provid':37 'releas':19 'schema':4,10,30,48,54,92,95 'sinc':79 'stabl':15 'support':24 'test':94 'tv4':57 'unlik':50 'use':12,56,60 'v5':80 'valid':11,46,49 'validjsonschema':42 'version':16","created_at":"2026-06-07T16:50:31.492079+00:00","updated_at":"2026-06-07T16:50:31.492079+00:00","problems":[{"fix":"Install Ajv v7: npm install ajv@7. If using ESM, use import Ajv from 'ajv'.","cause":"Ajv version mismatch or missing install; default import may be needed for ESM.","error":"TypeError: Ajv is not a constructor"},{"fix":"Validate the schema against JSON Schema meta-schema, or use .validJsonSchema assertion to check it first.","cause":"The schema itself is invalid (e.g., unknown type keyword or missing $schema).","error":"AssertionError: expected [object Object] to be valid json schema"},{"fix":"Ensure chai is installed: npm install chai. Use chai.use(require('chai-json-schema-ajv')) exactly.","cause":"Chai not installed or incorrectly imported; also could be due to chai-json-schema-ajv not being a proper plugin.","error":"TypeError: chai.use(...) is not a function"},{"fix":"Install Ajv: npm install ajv --save-dev","cause":"Ajv is not installed as a dependency.","error":"Error: Cannot find module 'ajv'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/up9cloud/chai-json-schema-ajv#readme","github":"https://github.com/up9cloud/chai-json-schema-ajv","docs":null,"changelog":null,"pypi":null,"npm":"chai-json-schema-ajv","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}