Registry / database / sqlite-jsonschema

sqlite-jsonschema

JSON →
library0.2.3jsnpmunverified

sqlite-jsonschema is a SQLite extension that adds JSON Schema validation functions directly into SQL queries. Current stable version is 0.2.3, released monthly. It provides functions like jsonschema_valid(), jsonschema_validate(), and jsonschema_version(). Unlike server-side JSON Schema libraries, it runs entirely within SQLite, enabling schema validation in SQL queries and triggers. The npm package wraps precompiled binaries for macOS, Windows, and Linux (x64 and arm64), and integrates with better-sqlite3 and node-sqlite3 via loadExtension(). Key differentiator: zero-dependency native extension for SQLite.

npm install sqlite-jsonschema
INSTALL
IMPORT
SIG · SQLITE-JSONSCHEMA
S
sqlite-jsonschema
databasejavascriptv0.2.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

getLoadablePath
import * as sqlite_jsonschema from 'sqlite-jsonschema'; const path = sqlite_jsonschema.getLoadablePath();
import { getLoadablePath } from 'sqlite-jsonschema'
The package exports a namespace, not individual functions. Use namespace import or require('sqlite-jsonschema') for CommonJS.
default import
import sqlite_jsonschema from 'sqlite-jsonschema'
import { getLoadablePath } from 'sqlite-jsonschema'
The default export is the same as the namespace import. Both work similarly.
CommonJS require
const sqlite_jsonschema = require('sqlite-jsonschema')
For CommonJS projects, use require with no destructuring.

Shows loading the extension and using JSON Schema validation functions with better-sqlite3.

import Database from 'better-sqlite3'; import * as sqlite_jsonschema from 'sqlite-jsonschema'; const db = new Database(':memory:'); db.loadExtension(sqlite_jsonschema.getLoadablePath()); // Create a table with JSON data db.exec('CREATE TABLE users (id INTEGER PRIMARY KEY, data TEXT)'); db.prepare('INSERT INTO users VALUES (?, ?)').run(1, '{"name":"Alice","age":30}'); // Validate JSON using jsonschema_valid db.prepare('SELECT jsonschema_valid(?, ?) AS valid').run('{"type":"object","properties":{"name":{"type":"string"},"age":{"type":"integer"}}}', '{"name":"Alice","age":30}'); // Output version const version = db.prepare('SELECT jsonschema_version()').pluck().get(); console.log('Version:', version);
Debug
Known issues
gotchaThe package requires a native SQLite client (better-sqlite3 or node-sqlite3). It does not work with pure JavaScript SQLite implementations like sql.js or better-sqlite3 WASM.
fix
Use better-sqlite3 or node-sqlite3 as the database driver.
affects: >=0.0.0
breakingPlatform-specific optional dependencies must be installed. If the platform is not supported (e.g., 32-bit or musl Linux), install fails silently or at runtime.
fix
Ensure your platform is listed in the supported platforms (darwin-x64/darwin-arm64/win32-x64/linux-x64). For unsupported platforms, consider compiling the extension manually.
affects: >=0.0.0
deprecatedThe function jsonschema_valid() returns a boolean; earlier alpha versions used jsonschema_validate() which returned a JSON object with errors.
fix
Use jsonschema_valid() for boolean validation. If you need error details, use jsonschema_validate() and check the result.
affects: >=0.2.0
gotchaWhen used with node-sqlite3, the loadExtension() call is asynchronous; you must wait for the callback before using the extension functions.
fix
Wrap db.loadExtension() in a Promise or use callback to ensure extension is loaded before queries.
affects: >=0.0.0
Errors
Common errors & fixes
Error: The specified module could not be found. \\?\C:\...\node_modules\sqlite-jsonschema\prebuilds\win32-x64\sqlite-jsonschema.node
Missing optional dependency for the platform or corrupted install.
fix
Reinstall the package with `npm install sqlite-jsonschema` to fetch the correct prebuild. Ensure Windows build tools (node-gyp) are not needed; the prebuild should be downloaded automatically.
Error: Cannot find module 'sqlite-jsonschema'
The package is not installed or the module resolution fails due to misconfigured import.
fix
Run `npm install sqlite-jsonschema` and ensure you are using the correct import: `import * as sqlite_jsonschema from 'sqlite-jsonschema'`
TypeError: db.loadExtension is not a function
Using a SQLite driver that does not support loadExtension (e.g., sql.js).
fix
Use better-sqlite3 or node-sqlite3. Example: `npm install better-sqlite3` then `import Database from 'better-sqlite3'`
Upgrade
Version history
0.2.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
14
Meta
1
OpenAI (training)
1
Resources
sqlite-jsonschema — npm install sqlite-jsonschema · libregistry