Registry / database / json-orm

json-orm

JSON →
library1.0.0jsnpmunverified

A lightweight, zero-dependency Node.js library (version 1.0.0, released 2023) for querying and manipulating JSON data structures using an ORM-like interface. Provides CRUD operations with both synchronous and asynchronous APIs, querying by key-value pairs with support for wildcards and regular expressions, dot-notation path access, and logical operators. Designed for simple JSON file persistence without a full database. Note: The package has only one version (1.0.0) and appears to be in an early stage, with minimal community adoption and infrequent updates.

npm install json-orm
INSTALL
IMPORT
SIG · JSON-ORM
J
json-orm
databasejavascriptv1.0.0
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.

JSONORM
const JSONORM = require('json-orm');
import JSONORM from 'json-orm';
Package does not provide ESM exports; only CommonJS is supported.
JSONORM
import JSONORM = require('json-orm');
In TypeScript with esModuleInterop, you can also do `import JSONORM from 'json-orm'`.
findSync
db.findSync({ keyName: 'role', value: 'admin' })
db.findSync('role', 'admin')
Query must be an object with 'keyName' and 'value' properties, not positional arguments.
updateSync
db.updateSync('path', [{ keyName: 'field', value: 'new' }])
db.updateSync('path', { keyName: 'field', value: 'new' })
updates must be an array of update objects, even for a single field.

Demonstrates synchronous and asynchronous querying, path-based access, and retrieval of objects from paths.

const JSONORM = require('json-orm'); const data = { users: [ { id: 1, name: 'John Doe', role: 'admin' }, { id: 2, name: 'Jane Smith', role: 'user' } ] }; const db = new JSONORM(data); // Find admins synchronously const admins = db.findSync({ keyName: 'role', value: 'admin' }); console.log('Found admins:', admins); // => Found admins: ['users.0'] // Get the actual object from the path const adminUser = db.getObject(admins[0]); console.log('Admin user:', adminUser); // => Admin user: { id: 1, name: 'John Doe', role: 'admin' } // Asynchronous find db.find({ keyName: 'name', value: 'Jane Smith' }) .then(results => console.log('Async result:', results)); // => Async result: [ 'users.1' ]
Debug
Known issues
gotchaThe `findSync` query must be an object with both `keyName` and `value`; no support for complex nested queries or nested path matching beyond direct key-value checks.
fix
Use the exact query format: { keyName: 'property', value: 'desiredValue' }.
affects: >=1.0.0
gotchaThe `updateSync` method requires an array of update objects even for a single field; passing a single object will cause an error.
fix
Wrap the update object in an array: `db.updateSync('path', [{ keyName: 'field', value: 'new' }])`.
affects: >=1.0.0
gotchaThe library does not automatically persist to disk; changes are only in memory. Use `db.saveToFile(path)` to write to disk.
fix
After modifying data, call `db.saveToFile('data.json')` to persist.
affects: >=1.0.0
gotchaNo built-in validation or schema enforcement; data integrity is entirely the user's responsibility.
fix
Implement your own validation logic before inserting/updating data.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: JSONORM is not a constructor
Using ES module import syntax with a CommonJS-only package.
fix
Use require: `const JSONORM = require('json-orm');`
findSync is not a function
Attempting to call findSync on an instance before calling new JSONORM(); or using wrong import.
fix
Ensure you instantiate the class: `const db = new JSONORM(data);` then call `db.findSync(...)`.
Cannot read properties of undefined (reading 'keyName')
Passing a string instead of an object to findSync.
fix
Use an object: `db.findSync({ keyName: 'role', value: 'admin' })`.
updates must be an array
Passing a single object to updateSync instead of an array.
fix
Wrap the update object in square brackets: `db.updateSync('path', [{ keyName: 'field', value: 'new' }])`.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
json-orm — npm install json-orm · libregistry