Registry / database / jsonsql

jsonsql

JSON →
library0.2.5jsnpmunverified

jsonSQL is a lightweight JavaScript library that allows querying JSON objects with a SQL-like syntax. It supports field selection (`*`, nested fields), conditions (`where`) with AND (`&&`), OR (`||`), grouping, and comparisons (`=`, `!=`, `like`, `!~`, `<`, `>`, `<=`, `>=`). Version 0.2.5 is the latest stable release. The library works with nested objects and arrays, supports date comparisons via timestamps, and returns matching objects as an array. It is designed for simple in-memory queries on JavaScript objects without a database, but has limited advanced features like aggregation or joins.

npm install jsonsql
INSTALL
IMPORT
SIG · JSONSQL
J
jsonsql
databasejavascriptv0.2.5
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.

default function
import jsonSQL from 'jsonsql'
const { default: jsonSQL } = require('jsonsql')
The package exports a single function. In CommonJS, use require('jsonSQL'). ESM import may need default import.
Query function (CommonJS)
const Query = require('jsonsql')
const { Query } = require('jsonsql')
CommonJS require returns the function directly; destructuring will not work.
TypeScript usage
import jsonsql from 'jsonsql'; const res: any[] = jsonsql(data, query);
import * as jsonsql from 'jsonsql'
The package has no type definitions; use any type or declare module.

Query a JSON object using SQL-like syntax: select all fields where age > 30.

import jsonsql from 'jsonsql'; const data = { '1': { name: 'Alice', age: 30 }, '2': { name: 'Bob', age: 25 }, '3': { name: 'Charlie', age: 35 } }; const query = '* where age>30'; const result = jsonsql(data, query); console.log(result); // Output: [ { name: 'Charlie', age: 35 } ]
Debug
Known issues
gotchaPackage uses 'require('jsonSQL')' with capital 'S' in examples, but npm package name is 'jsonsql' (lowercase). Import with correct casing.
fix
Use const Query = require('jsonsql'); (all lowercase)
affects: >=0.0.0
gotchaField path in select uses dot notation even for nested fields, e.g., '*.holy.addr'. The result flattens nested paths into keys like 'holy.addr' (string with dot).
fix
Access result fields using bracket notation: result['holy.addr']
affects: >=0.0.0
gotchaString values in conditions must not be quoted with single or double quotes; use bare strings (e.g., holy.name=CRAP).
fix
Write condition as 'holy.name=CRAP' not 'holy.name="CRAP"'
affects: >=0.0.0
gotchaDate comparison requires converting Date object to a number via valueOf() before concatenation.
fix
Use: where birth>' + new Date(2015,1,1).valueOf()
affects: >=0.0.0
deprecatedPackage has not been updated since 2016. No TypeScript definitions, no ESM support in package.json.
fix
Consider alternatives like jmespath or jsonpath
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: jsonsql is not a function
Importing the module incorrectly (e.g., using named import).
fix
Use default import: import jsonsql from 'jsonsql' or const jsonsql = require('jsonsql')
Upgrade
Version history
0.2.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
jsonsql — npm install jsonsql · libregistry