{"id":48293,"library":"json-schema-library","title":"json-schema-library","description":"json-schema-library is a customizable, hackable, and highly compliant JSON Schema validator and utility library for JavaScript/TypeScript, fully supporting JSON Schema drafts 04, 06, 07, 2019-09, and 2020-12. Version 11.5.0 is current (released 2024), with frequent updates. Unlike faster or more minimal validators, it prioritizes extensibility: you can customize drafts, add keyword extensions, and traverse schemas via SchemaNode. It's the most compliant validator per Bowtie reports, runs in Node and browser, and ships TypeScript types. Designed for developers building custom tools around JSON Schema, not just validation.","status":"active","version":"11.5.0","language":"javascript","source_language":"en","source_url":"https://github.com/sagold/json-schema-library","tags":["javascript","JSON","schema","customize","library","tools","utilities","validator","validation","typescript"],"install":[{"cmd":"npm install json-schema-library","lang":"bash","label":"npm"},{"cmd":"yarn add json-schema-library","lang":"bash","label":"yarn"},{"cmd":"pnpm add json-schema-library","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Deep clone, merge, and utility functions used internally","package":"lodash","optional":false},{"reason":"Unique identifiers for internal schema node tracking","package":"uuid","optional":true}],"imports":[{"note":"ESM-only since v11. For TypeScript, use import syntax. CommonJS require may fail in some bundlers or Node versions.","wrong":"const { compileSchema } = require('json-schema-library'); compileSchema(schema);","symbol":"compileSchema","correct":"import { compileSchema } from 'json-schema-library'"},{"note":"TypeScript type used for the result of compileSchema. Not available as a runtime value.","symbol":"SchemaNode","correct":"import { SchemaNode } from 'json-schema-library'"},{"note":"Draft imports are lowercase, camelCase. Use draftXX to access draft-specific validation functions.","wrong":"import { Draft04 } from 'json-schema-library'","symbol":"draft04","correct":"import { draft04 } from 'json-schema-library'"},{"note":"Default export is the library namespace; prefer named imports for tree-shaking.","wrong":"import * as jsonSchemaLibrary from 'json-schema-library'","symbol":"default","correct":"import jsonSchemaLibrary from 'json-schema-library'"}],"quickstart":{"code":"import { compileSchema } from 'json-schema-library';\n\nconst schema = {\n  type: 'object',\n  properties: {\n    name: { type: 'string' },\n    age: { type: 'number', minimum: 0 }\n  },\n  required: ['name']\n};\n\nconst compiled = compileSchema(schema);\n\n// Validate data\nconst data = { name: 'Alice', age: 30 };\nconst result = compiled.validate(data);\nconsole.log('Valid:', result.valid); // true\n\n// Generate default data\nconst defaultData = compiled.getData();\nconsole.log(defaultData); // {}\n\n// Access a node by JSON Pointer\nconst nameNode = compiled.getNode('/properties/name');\nconsole.log(nameNode.schema); // { type: 'string' }","lang":"typescript","description":"Compiles a JSON Schema into a SchemaNode, validates data, generates default data, and navigates subschemas via JSON Pointer."},"warnings":[{"fix":"Use ES modules: static import or dynamic import(). For legacy CommonJS, stick with v10.x.","message":"Version 11 dropped CommonJS support. require('json-schema-library') may fail in older Node or non-ESM environments.","severity":"breaking","affected_versions":">=11.0.0"},{"fix":"Update code to destructure result: const { valid, errors } = schemaNode.validate(data);","message":"The `validate` method on SchemaNode now returns an object with `valid`, `errors`, `annotations`. The old method returning boolean is removed.","severity":"deprecated","affected_versions":">=8.0.0"},{"fix":"Parse JSON strings with JSON.parse() first, or import JSON files using import assertions (build tools) or fs.readFileSync with JSON.parse.","message":"compileSchema expects a JSON Schema object, not a JSON string or file path. Attempting to pass a string will throw a confusing error.","severity":"gotcha","affected_versions":"*"},{"fix":"Explicitly pass draft option: compileSchema(schema, { draft: 'draft-04' }) to force a specific draft.","message":"When using draft-04, the `$schema` keyword in the schema object may be ignored if not set correctly; the library auto-detects based on draft. But if you explicitly set draft via options, it overrides $schema.","severity":"gotcha","affected_versions":"*"},{"fix":"Change getNode('#/foo') to getNode('#/foo', { data: {} }) to avoid deprecated behavior.","message":"getNode() with a single string argument is deprecated. Use the overload with options object for better type safety.","severity":"deprecated","affected_versions":">=10.0.0"}],"env_vars":null,"search_vec":"'-09':33 '-12':36 '04':29 '06':30 '07':31 '11.5.0':38 '2019':32 '2020':35 '2024':42 'add':59 'around':91 'bowti':74 'browser':80 'build':88 'compliant':15,71 'current':40 'custom':57,89,100 'customiz':11 'design':85 'develop':87 'draft':28,58 'extens':54,61 'faster':47 'frequent':44 'fulli':24 'hackabl':12 'high':14 'javascript':97 'javascript/typescript':23 'json':2,6,16,26,92,98 'json-schema-librari':1,5 'keyword':60 'librari':4,8,21,101 'minim':50 'node':78 'per':73 'priorit':53 'releas':41 'report':75 'run':76 'schema':3,7,17,27,64,93,99 'schemanod':66 'ship':82 'support':25 'tool':90,102 'travers':63 'type':84 'typescript':83,106 'unlik':46 'updat':45 'util':20,103 'valid':18,51,72,96,104,105 'version':37 'via':65","created_at":"2026-06-07T16:55:53.844820+00:00","updated_at":"2026-06-07T16:55:53.844820+00:00","problems":[{"fix":"Ensure you call compileSchema(schema) first and use the returned SchemaNode. Check import: import { compileSchema } from 'json-schema-library'.","cause":"You may have imported a version that doesn't export SchemaNode correctly, or you're using v11 and trying to call validate on a raw schema object.","error":"TypeError: schemaNode.validate is not a function"},{"fix":"Update tsconfig.json: set 'moduleResolution' to 'node' or 'node16', and 'esModuleInterop' to true. Also ensure json-schema-library is installed.","cause":"Missing @types/json-schema-library (unnecessary since v10 ships types) or incorrect module resolution in tsconfig.","error":"Cannot find module 'json-schema-library' or its corresponding type declarations"},{"fix":"Validate your schema first with a JSON Schema validator or check that properties is an object (not array or string).","cause":"The schema passed to compileSchema is invalid JSON Schema structure (likely malformed).","error":"Uncaught Error: Invalid schema: property 'properties' must be an object"},{"fix":"Upgrade to v10+ or use a polyfill for self: globalThis.self = globalThis;","cause":"The library is trying to access the global object in a Node environment where `self` doesn't exist. This is a known bug in older versions (pre-v10).","error":"ReferenceError: self is not defined"}],"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/sagold/json-schema-library","github":"https://github.com/sagold/json-schema-library","docs":null,"changelog":null,"pypi":null,"npm":"json-schema-library","openapi_spec":null,"status_page":null,"smithery":null,"categories":["validation"],"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}}