Registry / database / json-sql-utility

json-sql-utility

JSON →
library1.1.4jsnpmunverified

A lightweight utility for converting JSON objects to SQL SELECT queries. Currently at version 1.1.4, it supports SELECT statements with fields, aggregations, WHERE clauses (including logical operators, date ranges), GROUP BY, ORDER BY, and misc clauses. It is not actively maintained and only supports SELECT queries; INSERT, UPDATE, DELETE are absent. Simpler than alternatives like json-sql or squel, but with limited features.

npm install json-sql-utility
INSTALL
IMPORT
SIG · JSON-SQL-UTILITY
J
json-sql-utility
databasejavascriptv1.1.4
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.

select
import { select } from 'json-sql-utility'
const select = require('json-sql-utility')
ESM-only; CommonJS require is not supported. The package has no default export.
select
const { select } = require('json-sql-utility')
import select from 'json-sql-utility'
If using CommonJS, destructure from require. Default import is incorrect.
select
import { select } from 'json-sql-utility'
import * as sql from 'json-sql-utility'
Wildcard import works, but only the `select` function is exported.

Builds a SELECT SQL query from a JSON object with fields, aggregation, WHERE conditions, grouping, ordering, and misc clauses.

import { select } from 'json-sql-utility'; const query = select({ fields: ['A', 'B'], aggregation: [ { fn: 'count', args: 'D', alias: 'CNT' } ], from: 'STUDENTS', where: [ { operator: 'equal', field: 'NAME', value: 'Piyush' }, { operator: '=', field: 'ROLL', value: [13], }, { operator: 'OR', conditions: [ { operator: 'equal', field: 'A', value: 5, }, { operator: 'equal', field: 'A', value: 10, } ] }, { operator: 'dateBetween', field: 'BIRTH', value: { start: new Date(1975, 0, 1), end: new Date(1999, 11, 31), } }, ], groupBy: ['A', 'B', 'C'], orderBy: ['A'], misc: [ "EXTERNAL NAME 'TestFuncs$MyMath.pow'" ], }); console.log(query);
Debug
Known issues
breakingThe package only supports SELECT queries. Trying to build INSERT, UPDATE, or DELETE will fail or produce garbage.
fix
Use a different library like knex.js or json-sql for full SQL support.
affects: >=1.0.0
gotchaThe `where` operator names use strings like 'equal', '=', 'dateBetween', etc. Using an unsupported operator will silently produce invalid SQL.
fix
Check the source or documentation for supported operators. Only a limited set is implemented.
affects: >=1.0.0
gotchaDate values in where conditions are serialized using toLocaleDateString, which may produce locale-dependent strings like '1/1/1975'. This may not match your SQL dialect's expected format.
fix
Pass dates as ISO strings (e.g., '1975-01-01') to ensure consistent formatting.
affects: >=1.0.0
deprecatedThe package has not been updated since 2020. There are known issues with SQL injection if using raw values.
fix
Sanitize inputs manually or migrate to a maintained alternative.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: select is not a function
Importing default export instead of named export.
fix
Use `import { select } from 'json-sql-utility'`
ReferenceError: require is not defined
Using require in an ESM environment.
fix
Use `import { select } from 'json-sql-utility'`
SyntaxError: Unexpected token '.'
Using CommonJS require incorrectly (e.g., `const sql = require('json-sql-utility'); sql.select(...)` but the package has no default export).
fix
Use `const { select } = require('json-sql-utility')`
Upgrade
Version history
1.1.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources
json-sql-utility — npm install json-sql-utility · libregistry