{"id":47244,"library":"chai-json-schema","title":"chai-json-schema","description":"Chai plugin for validating values against JSON Schema v4. Current stable version 1.5.1, maintained as a legacy plugin using Tiny Validator tv4 for schema validation. Supports draft-04 only, with no support for later drafts. Key differentiator: provides BDD and TDD assertions directly in Chai tests. Release cadence is low; last release was 2019. Consider chai-json-schema-ajv for newer JSON Schema versions.","status":"maintenance","version":"1.5.1","language":"javascript","source_language":"en","source_url":"https://github.com/chaijs/chai-json-schema","tags":["javascript","array","assert","assertion","browser","chai","chai-plugin","json","json-schema"],"install":[{"cmd":"npm install chai-json-schema","lang":"bash","label":"npm"},{"cmd":"yarn add chai-json-schema","lang":"bash","label":"yarn"},{"cmd":"pnpm add chai-json-schema","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required for plugin functionality","package":"chai","optional":false}],"imports":[{"note":"CommonJS require is standard. ESM import may not work due to CJS-only exports.","wrong":"import chaiJsonSchema from 'chai-json-schema';","symbol":"default (plugin)","correct":"const chai = require('chai'); chai.use(require('chai-json-schema'));"},{"note":"Order is value then schema; ensure correct argument order.","wrong":"assert.jsonSchema(schema, value);","symbol":"assert.jsonSchema","correct":"const assert = require('chai').assert; assert.jsonSchema(value, schema);"},{"note":"BDD style uses chainable getter; value is subject, schema is argument.","wrong":"expect(schema).to.be.jsonSchema(value);","symbol":"expect().to.be.jsonSchema","correct":"expect(value).to.be.jsonSchema(schema);"}],"quickstart":{"code":"const chai = require('chai');\nchai.use(require('chai-json-schema'));\nconst expect = chai.expect;\n\nconst fruitSchema = {\n  type: 'object',\n  required: ['name', 'color'],\n  properties: {\n    name: { type: 'string' },\n    color: { type: 'string' }\n  }\n};\n\nexpect({ name: 'apple', color: 'red' }).to.be.jsonSchema(fruitSchema);\nexpect({ name: 42 }).to.not.be.jsonSchema(fruitSchema);\n\n// Using assert:\nconst assert = chai.assert;\nassert.jsonSchema({ name: 'banana', color: 'yellow' }, fruitSchema);","lang":"javascript","description":"Demonstrates BDD and TDD assertions for JSON Schema validation using chai-json-schema."},"warnings":[{"fix":"Switch to chai-json-schema-ajv for later drafts.","message":"Uses tv4, which only supports JSON Schema draft-04. Not compatible with draft-06/07/2019-09/2020-12.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Use chai.tv4.addSchema(uri, schema) before asserting.","message":"Schema $ref requires pre-adding schemas via chai.tv4.addSchema(). Inline $ref will fail if not added.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Monitor for CVEs; consider alternative libraries like ajv + chai-json-schema-ajv.","message":"tv4 is not actively maintained. Potential security vulnerabilities in the dependency chain.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure tv4 global is available and jsonpointer is required as 'jsonpointer'.","message":"AMD or browser usage requires manual loading of jsonpointer and tv4 shims.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'-04':32 '1.5.1':17 '2019':58 'ajv':64 'array':71 'assert':46,72,73 'bdd':43 'browser':74 'cadenc':52 'chai':2,5,49,61,75,77 'chai-json-schema':1 'chai-json-schema-ajv':60 'chai-plugin':76 'consid':59 'current':14 'differenti':41 'direct':47 'draft':31,39 'javascript':70 'json':3,11,62,67,79,81 'json-schema':80 'key':40 'last':55 'later':38 'legaci':21 'low':54 'maintain':18 'newer':66 'plugin':6,22,78 'provid':42 'releas':51,56 'schema':4,12,28,63,68,82 'stabl':15 'support':30,36 'tdd':45 'test':50 'tini':24 'tv4':26 'use':23 'v4':13 'valid':8,25,29 'valu':9 'version':16,69","created_at":"2026-06-07T16:50:31.514744+00:00","updated_at":"2026-06-07T16:50:31.514744+00:00","problems":[{"fix":"Install chai as dependency: npm install chai. Then require('chai') before use.","cause":"Using chai-json-schema without importing chai first or incorrect chai version.","error":"TypeError: chai.use is not a function"},{"fix":"Use chai.tv4.addSchema('http://example.com/schema', schema) to pre-register referenced schemas.","cause":"$ref points to a schema not added via tv4.addSchema().","error":"Error: Invalid schema: unknown schema reference: #/definitions/..."},{"fix":"Validate schema itself with tv4.validate(schema, tv4.getSchema('http://json-schema.org/draft-04/schema#')) or use online validator.","cause":"Schema definition error or value does not match schema.","error":"AssertionError: expected { Object (name, color) } to be json schema"}],"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":"http://chaijs.com","github":"https://github.com/chaijs/chai-json-schema","docs":null,"changelog":null,"pypi":null,"npm":"chai-json-schema","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}}