Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:APIJSON APIJSON Demo JSON To SQL Translation

From Leeroopedia
Knowledge Sources
Domains API_Design, Database, ORM
Last Updated 2026-10-14 00:00 GMT

Overview

Architectural pattern that translates structured JSON HTTP requests into SQL queries automatically, allowing clients to query and manipulate database records without writing SQL or knowing the underlying schema.

Description

JSON-to-SQL Translation is the core innovation of the APIJSON framework. Instead of building fixed REST endpoints for each resource, a single generic endpoint accepts structured JSON requests that describe what data to retrieve or modify. The server parses the JSON, enforces access control, generates the corresponding SQL, executes it, and returns the results as structured JSON.

This solves several problems:

  • Eliminates boilerplate CRUD code: No need to write separate controller methods for each table and operation.
  • Enables flexible queries: Clients can request nested relations, filtered columns, aggregated counts, and joins in a single request — all described in JSON.
  • Centralizes security: Access control and field validation happen at the framework level, not per-endpoint.

The translation pipeline flows: HTTP Request → JSON Parsing → Access Verification → SQL Configuration Generation → SQL Execution → Response Assembly.

Usage

Use this principle when building data-driven APIs where:

  • Clients need flexible, dynamic queries over many tables without per-endpoint development.
  • The API should support CRUD operations generically, driven by request structure rather than URL paths.
  • Nested relational data should be retrievable in a single round-trip (e.g., a User and their Comments in one request).

It is the foundational pattern of the APIJSON framework and replaces traditional REST or GraphQL approaches with a JSON-centric declarative model.

Theoretical Basis

The translation follows a pipeline of transformations, each operating on a structured intermediate representation:

Client JSON Request
    │
    ▼
[1] Parse: Extract tables, columns, conditions, relations from JSON
    │
    ▼
[2] Verify: Check role permissions (@MethodAccess) and field regex validation
    │
    ▼
[3] Configure: Build SQLConfig (table, method, conditions, joins, columns)
    │
    ▼
[4] Execute: Generate SQL string, execute via connection pool, cache results
    │
    ▼
[5] Assemble: Apply remote functions, format response JSON
    │
    ▼
Structured JSON Response

Key JSON keywords that drive translation:

  • @method: Overrides the HTTP method for a sub-request (e.g., `"@method": "POST"`)
  • @column: Selects specific columns (e.g., `"@column": "id,name,sex"`)
  • @condition: / inline key-value pairs map to WHERE clauses
  • {} array operator: Expresses IN clauses and complex conditions (e.g., `"id{}": [1, 2, 3]`)
  • @role: Sets the assumed role for permission checks (e.g., `"@role": "OWNER"`)
  • Ref paths: Nested objects map to JOINs (e.g., `"User": { "Comment": { ... } }`)

The framework generates standard SQL (SELECT, INSERT, UPDATE, DELETE) from these JSON structures, with database-specific dialect handling (MySQL, PostgreSQL, Oracle, etc.).

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment