{"id":18340,"library":"express-jsonschema","title":"express-jsonschema","description":"Express middleware for JSON Schema validation, currently at version 1.1.6. It leverages the jsonschema library to validate request bodies against JSON Schema v4. The library provides a simple validate() middleware that attaches validation results to req.validations. Error handling is left to the developer, allowing custom responses. Compared to express-validator or Joi, this library decouples validation logic from schema definitions. It is in maintenance mode, with the last release in 2016 and no recent updates.","status":"maintenance","version":"1.1.6","language":"javascript","source_language":"en","source_url":"git://github.com/trainiac/express-jsonschema","tags":["javascript","express","jsonschema","validation","validate"],"install":[{"cmd":"npm install express-jsonschema","lang":"bash","label":"npm"},{"cmd":"yarn add express-jsonschema","lang":"bash","label":"yarn"},{"cmd":"pnpm add express-jsonschema","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core validation library; express-jsonschema wraps jsonschema to provide Express middleware.","package":"jsonschema","optional":false}],"imports":[{"note":"The default export is an object; validate is a named export. CommonJS only.","wrong":"const validate = require('express-jsonschema');","symbol":"validate","correct":"const validate = require('express-jsonschema').validate;"},{"note":"JsonSchemaValidation is a class used for error handling; it is not a default export.","wrong":"const { JsonSchemaValidation } = require('express-jsonschema');","symbol":"JsonSchemaValidation","correct":"const JsonSchemaValidation = require('express-jsonschema').JsonSchemaValidation;"},{"note":"ESM imports are supported but not documented; use named import.","wrong":"import validate from 'express-jsonschema';","symbol":"validate (ESM)","correct":"import { validate } from 'express-jsonschema';"}],"quickstart":{"code":"const express = require('express');\nconst { validate } = require('express-jsonschema');\nconst app = express();\napp.use(require('body-parser').json());\n\nconst schema = {\n  type: 'object',\n  properties: {\n    name: { type: 'string' },\n    age: { type: 'number' }\n  },\n  required: ['name']\n};\n\napp.post('/user', validate({ body: schema }), (req, res) => {\n  res.json({ valid: true });\n});\n\napp.use((err, req, res, next) => {\n  if (err.name === 'JsonSchemaValidation') {\n    res.status(400).json({ errors: err.validations });\n  } else {\n    next(err);\n  }\n});\n\napp.listen(3000);","lang":"javascript","description":"Demonstrates setting up an Express endpoint with JSON Schema validation for the request body and a custom error handler."},"warnings":[{"fix":"Use validate({ body: schema }) instead of validate(schema).","message":"The validate() function expects an object with keys 'body', 'query', or 'params' - not just a schema object.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Add Express error middleware checking for err.name === 'JsonSchemaValidation'.","message":"Error handling must be explicitly implemented; unhandled validation errors will crash the app.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Consider migrating to @express-validator/express-validator or joi-based middleware.","message":"The project has not been updated since 2016 and does not support modern Express versions (4.17+).","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use const { validate } = require('express-jsonschema');","cause":"Attempted to use default import without destructuring.","error":"TypeError: validate is not a function"},{"fix":"Pass an object with key 'body', 'query', or 'params'.","cause":"The validate() call is missing the request property key, e.g., validate({ body: schema }).","error":"Cannot read property 'body' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}