{"id":48258,"library":"json-rest-schema","title":"json-rest-schema","description":"A flexible schema validation library for JavaScript objects, designed for REST APIs and beyond. Version 1.0.16 supports Node >=18.0.0. Key features include type casting (e.g., string to number), data transformation (trimming whitespace), and a pluggable architecture for custom rules. Unlike many validators, it offers create/replace/patch semantics, nested object and array validation, recursive runtime validation, and adapters for React Hook Form, Vue+Vuetify, and VeeValidate. The library returns a flat error map with dotted paths for nested fields, making it easy to associate errors with UI components.","status":"active","version":"1.0.16","language":"javascript","source_language":"en","source_url":"https://github.com/mobily-enterprises/json-rest-schema","tags":["javascript","schema","validation","json","rest-api","data-validation","type-casting","data-transformation","plugin"],"install":[{"cmd":"npm install json-rest-schema","lang":"bash","label":"npm"},{"cmd":"yarn add json-rest-schema","lang":"bash","label":"yarn"},{"cmd":"pnpm add json-rest-schema","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only module; CJS require() will fail with ERR_REQUIRE_ESM.","wrong":"const createSchema = require('json-rest-schema')","symbol":"createSchema","correct":"import { createSchema } from 'json-rest-schema'"},{"note":"Type import only for TypeScript; not a runtime export.","wrong":"import { Schema } from 'json-rest-schema'","symbol":"Schema","correct":"import type { Schema } from 'json-rest-schema'"},{"note":"Type for the return value { validatedObject, errors }.","wrong":null,"symbol":"ValidationResult","correct":"import type { ValidationResult } from 'json-rest-schema'"}],"quickstart":{"code":"import { createSchema } from 'json-rest-schema';\n\nconst userSchema = createSchema({\n  username: { type: 'string', required: true, minLength: 3 },\n  email: { type: 'string', required: true },\n  age: { type: 'number', min: 18, defaultTo: 18 }\n});\n\nconst userInput = {\n  username: '  alex ',\n  email: 'alex@example.com',\n  age: '25'\n};\n\nconst { validatedObject, errors } = userSchema.create(userInput);\n\nif (Object.keys(errors).length > 0) {\n  console.log('Validation failed!', errors);\n} else {\n  console.log('Validation successful!', validatedObject);\n}\n// validatedObject: { username: 'alex', email: 'alex@example.com', age: 25 }","lang":"javascript","description":"Create a schema, validate user input with type casting and transformation, and handle errors."},"warnings":[{"fix":"Use import syntax (ESM) or dynamic import().","message":"ESM-only module: require() will throw ERR_REQUIRE_ESM.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Upgrade Node.js to version 18 or later.","message":"Node.js >=18.0.0 required; older versions will fail with SyntaxError for top-level await or ESM syntax.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Use Object.keys(errors) or for...in to iterate errors, not .get/.set methods.","message":"The 'errors' object is a plain object (not a Map) despite documentation describing it as 'a map'. Do not treat it as a Map.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Always use the full dot-separated path as the key in errors.","message":"Field names in errors use dot notation for nested paths (e.g., 'address.city'). Accessing via path string is correct but may be unintuitive for deeply nested arrays (e.g., 'items.0.name').","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Manually cast non-primitive types in custom rules or preprocess data.","message":"Type casting only applies to primitive types (string, number, boolean); it does not cast objects or arrays.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.0.16':20 '18.0.0':23 'adapt':60 'api':16,97 'architectur':40 'array':54 'associ':86 'beyond':18 'cast':28,103 'compon':90 'create/replace/patch':49 'custom':42 'data':33,99,105 'data-transform':104 'data-valid':98 'design':13 'dot':77 'e.g':29 'easi':84 'error':74,87 'featur':25 'field':81 'flat':73 'flexibl':6 'form':64 'hook':63 'includ':26 'javascript':11,91 'json':2,94 'json-rest-schema':1 'key':24 'librari':9,70 'make':82 'mani':45 'map':75 'nest':51,80 'node':22 'number':32 'object':12,52 'offer':48 'path':78 'pluggabl':39 'plugin':107 'react':62 'recurs':56 'rest':3,15,96 'rest-api':95 'return':71 'rule':43 'runtim':57 'schema':4,7,92 'semant':50 'string':30 'support':21 'transform':34,106 'trim':35 'type':27,102 'type-cast':101 'ui':89 'unlik':44 'valid':8,46,55,58,93,100 'veevalid':68 'version':19 'vue':65 'vuetifi':66 'whitespac':36","created_at":"2026-06-07T16:55:42.231795+00:00","updated_at":"2026-06-07T16:55:42.231795+00:00","problems":[{"fix":"Change to import statement or use dynamic import().","cause":"Using CommonJS require() with an ESM-only package.","error":"ERR_REQUIRE_ESM"},{"fix":"Upgrade Node.js to >=18.0.0.","cause":"Running the module in a Node.js version <18 that doesn't support ESM syntax.","error":"SyntaxError: Unexpected token 'export'"},{"fix":"Check that the error object exists and has the expected structure before accessing properties like .field.","cause":"Attempting to access a property on an error value that may be undefined or malformed.","error":"TypeError: Cannot read properties of undefined (reading 'field')"},{"fix":"Register a custom type handler using the plugin API before using it in a schema.","cause":"Using a type in the schema that has not been registered via the plugin system.","error":"Error: unknown type handler for 'customType'"}],"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://mobily-enterprises.github.io/json-rest-schema/","github":"https://github.com/mobily-enterprises/json-rest-schema","docs":null,"changelog":null,"pypi":null,"npm":"json-rest-schema","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"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}}