The official JavaScript/TypeScript SDK for jsondb.cloud — a hosted JSON document database.
npm install @jsondb-cloud/clientimport { JsonDB } from "@jsondb-cloud/client";
const db = new JsonDB({ apiKey: "jdb_sk_live_xxxx" });
const users = db.collection<{ name: string; email: string }>("users");
// Create
const alice = await users.create({ name: "Alice", email: "alice@example.com" });
// Read
const user = await users.get(alice._id);
// List with filter
const admins = await users.list({
filter: { role: "admin" },
sort: "-$createdAt",
limit: 10,
});
// Update
await users.patch(alice._id, { email: "alice@newdomain.com" });
// Delete
await users.delete(alice._id);| Option | Type | Default | Description |
|---|---|---|---|
apiKey |
string |
— | Required. API key (jdb_sk_live_... or jdb_sk_test_...) |
project |
string |
"v1" |
Project identifier |
baseUrl |
string |
"https://api.jsondb.cloud" |
API base URL |
timeout |
number |
30000 |
Request timeout in milliseconds |
retry |
object |
{ enabled: true, maxRetries: 3 } |
Retry with exponential backoff |
headers |
Record<string, string> |
{} |
Extra headers for every request |
fetch |
typeof fetch |
globalThis.fetch |
Custom fetch implementation |
create(doc, options?)— Create a documentget(id)— Get a document by IDlist(options?)— List documents with filtering, sorting, paginationcount(filter?)— Count documents matching an optional filterupdate(id, doc)— Replace a document entirelypatch(id, partial)— Partial update (merge-patch)jsonPatch(id, operations)— Apply JSON Patch operations (RFC 6902)delete(id)— Delete a document
where(field, op, value)— Start a fluent query (==,!=,>,>=,<,<=,contains,in)orderBy(field)— Sort resultslimit(n)/offset(n)— Paginateselect(...fields)— Pick fieldsexec()— Execute the query
bulk(operations)— Execute mixed bulk operationsbulkCreate(docs)— Create multiple documents
setSchema(schema)— Set a JSON Schema for the collectiongetSchema()— Get the current schemaremoveSchema()— Remove the schemavalidate(doc)— Validate a document without storing
listVersions(id)— List all versions of a documentgetVersion(id, version)— Get a document at a specific versionrestoreVersion(id, version)— Restore to a specific versiondiffVersions(id, from, to)— Diff two versions
createWebhook(options)— Register a webhooklistWebhooks()— List all webhooksgetWebhook(id)— Get webhook details with recent deliveriesupdateWebhook(id, options)— Update a webhookdeleteWebhook(id)— Delete a webhooktestWebhook(id)— Send a test event
importDocuments(docs, options?)— Import documents (fail/skip/overwrite on conflict)exportDocuments(options?)— Export all documents
stream(options?)— Subscribe to real-time changes via SSE- Events:
created,updated,deleted,change
- Events:
import { JsonDB, NotFoundError, ValidationError } from "@jsondb-cloud/client";
try {
const user = await users.get("nonexistent");
} catch (err) {
if (err instanceof NotFoundError) {
console.log("Document not found:", err.documentId);
}
}All errors extend JsonDBError which has .code, .status, and .details properties.
| Error | Status | Code |
|---|---|---|
NotFoundError |
404 | DOCUMENT_NOT_FOUND |
ValidationError |
400 | VALIDATION_FAILED |
ConflictError |
409 | CONFLICT |
UnauthorizedError |
401 | UNAUTHORIZED |
ForbiddenError |
403 | FORBIDDEN |
RateLimitError |
429 | RATE_LIMITED |
QuotaExceededError |
429 | QUOTA_EXCEEDED |
DocumentTooLargeError |
413 | DOCUMENT_TOO_LARGE |
ServerError |
500 | INTERNAL_ERROR |
Full documentation at jsondb.cloud/docs.
| Package | Description |
|---|---|
| @jsondb-cloud/client | JavaScript/TypeScript SDK |
| @jsondb-cloud/mcp | MCP server for AI agents |
| @jsondb-cloud/cli | CLI tool |
| jsondb-cloud (PyPI) | Python SDK |
MIT