This documents the JSON output of lp_ast_to_json() and lp_parse_result_to_json().
Every AST node serializes as a JSON object with:
{
"kind": "STMT_SELECT",
"pos": {"line": 1, "col": 1, "offset": 0},
...
}kind(string): Node type name (e.g.,"STMT_SELECT","EXPR_LITERAL_INT")pos(object, optional): Source position — omitted if line is 0
Optional/NULL fields are omitted from output. Empty lists are omitted.
lp_parse_result_to_json() produces:
{
"statements": [ ... ],
"errors": [
{
"code": "syntax",
"message": "1:5: near \"GARBAGE\": syntax error",
"pos": {"line": 1, "col": 5, "offset": 4},
"end_pos": {"line": 1, "col": 12, "offset": 11}
}
]
}Error codes: "syntax", "illegal_token", "incomplete", "stack_overflow".
{
"kind": "STMT_SELECT",
"distinct": false,
"result_columns": [...],
"from": { ... },
"where": { ... },
"group_by": [...],
"having": { ... },
"window_defs": [...],
"order_by": [...],
"limit": { ... },
"with": { ... }
}{
"kind": "COMPOUND_SELECT",
"op": "UNION ALL",
"left": { ... },
"right": { ... }
}Operators: "UNION", "UNION ALL", "INTERSECT", "EXCEPT".
{
"kind": "STMT_INSERT",
"table": "users",
"schema": "main",
"alias": "u",
"or_conflict": "REPLACE",
"columns": [...],
"source": { ... },
"upsert": { ... },
"returning": [...]
}or_conflict: "ABORT", "FAIL", "IGNORE", "REPLACE", "ROLLBACK", or omitted.
{
"kind": "STMT_UPDATE",
"table": "users",
"schema": "main",
"alias": "u",
"or_conflict": "IGNORE",
"set_clauses": [...],
"from": { ... },
"where": { ... },
"order_by": [...],
"limit": { ... },
"returning": [...]
}{
"kind": "STMT_DELETE",
"table": "users",
"schema": "main",
"alias": "u",
"where": { ... },
"order_by": [...],
"limit": { ... },
"returning": [...]
}{
"kind": "STMT_CREATE_TABLE",
"name": "users",
"schema": "main",
"if_not_exists": false,
"temp": false,
"options": 0,
"columns": [...],
"constraints": [...],
"as_select": { ... }
}options: bitmask — 1 = WITHOUT ROWID, 2 = STRICT.
{
"kind": "STMT_CREATE_INDEX",
"name": "idx_email",
"schema": "main",
"table": "users",
"is_unique": true,
"if_not_exists": false,
"columns": [...],
"where": { ... }
}{
"kind": "STMT_CREATE_VIEW",
"name": "active_users",
"schema": "main",
"if_not_exists": false,
"temp": false,
"col_names": [...],
"select": { ... }
}{
"kind": "STMT_CREATE_TRIGGER",
"name": "trg_audit",
"schema": "main",
"if_not_exists": false,
"temp": false,
"time": "BEFORE",
"event": "INSERT",
"table_name": "users",
"update_columns": [...],
"when": { ... },
"body": [...]
}time: "BEFORE", "AFTER", "INSTEAD OF".
event: "INSERT", "DELETE", "UPDATE".
{
"kind": "STMT_CREATE_VTABLE",
"name": "docs",
"schema": "main",
"if_not_exists": false,
"module": "fts5",
"module_args": "title, body, content='documents'"
}{
"kind": "STMT_DROP",
"target": "TABLE",
"name": "users",
"schema": "main",
"if_exists": true
}target: "TABLE", "INDEX", "VIEW", "TRIGGER".
{"kind": "STMT_BEGIN", "trans_type": "IMMEDIATE"}trans_type: "DEFERRED", "IMMEDIATE", "EXCLUSIVE", or "".
{"kind": "STMT_COMMIT"}
{"kind": "STMT_ROLLBACK"}{"kind": "STMT_SAVEPOINT", "name": "sp1"}{
"kind": "STMT_PRAGMA",
"name": "journal_mode",
"schema": "main",
"value": "WAL"
}{"kind": "STMT_VACUUM", "schema": "main", "into": { ... }}{"kind": "STMT_REINDEX", "name": "users", "schema": "main"}{
"kind": "STMT_ATTACH",
"filename": { ... },
"dbname": { ... },
"key": { ... }
}{"kind": "STMT_DETACH", "dbname": { ... }}{
"kind": "STMT_ALTER",
"alter_type": "RENAME_TABLE",
"table_name": "users",
"schema": "main",
"new_name": "people",
"column_name": "old_col",
"column_def": { ... }
}alter_type: "RENAME_TABLE", "ADD_COLUMN", "DROP_COLUMN", "RENAME_COLUMN".
{
"kind": "STMT_EXPLAIN",
"is_query_plan": true,
"stmt": { ... }
}{"kind": "EXPR_LITERAL_INT", "value": "42"}
{"kind": "EXPR_LITERAL_STRING", "value": "hello"}{"kind": "EXPR_LITERAL_NULL"}{"kind": "EXPR_COLUMN_REF", "column": "id", "table": "users", "schema": "main"}{
"kind": "EXPR_BINARY_OP",
"op": "ADD",
"left": { ... },
"right": { ... },
"escape": { ... }
}escape is only present for LIKE/GLOB operations.
{"kind": "EXPR_UNARY_OP", "op": "MINUS", "operand": { ... }}{
"kind": "EXPR_FUNCTION",
"name": "COUNT",
"distinct": false,
"args": [...],
"order_by": [...],
"filter": { ... },
"over": { ... }
}{"kind": "EXPR_CAST", "expr": { ... }, "type_name": "TEXT"}{"kind": "EXPR_COLLATE", "expr": { ... }, "collation": "NOCASE"}{"kind": "EXPR_BETWEEN", "is_not": false, "expr": { ... }, "low": { ... }, "high": { ... }}{"kind": "EXPR_IN", "is_not": false, "expr": { ... }, "values": [...], "select": { ... }}Either values or select is present, not both.
{"kind": "EXPR_EXISTS", "select": { ... }}{"kind": "EXPR_SUBQUERY", "select": { ... }}{
"kind": "EXPR_CASE",
"operand": { ... },
"when_exprs": [...],
"else_expr": { ... }
}{"kind": "EXPR_RAISE", "type": "ABORT", "message": { ... }}{"kind": "EXPR_VARIABLE", "name": "?1"}{"kind": "EXPR_STAR", "table": "t"}{"kind": "EXPR_VECTOR", "values": [...]}{"kind": "RESULT_COLUMN", "expr": { ... }, "alias": "total"}{
"kind": "FROM_TABLE",
"name": "users",
"schema": "main",
"alias": "u",
"indexed_by": "idx_email",
"not_indexed": true,
"func_args": [...]
}{"kind": "FROM_SUBQUERY", "select": { ... }, "alias": "sub"}{
"kind": "JOIN_CLAUSE",
"join_type": "LEFT",
"left": { ... },
"right": { ... },
"on_expr": { ... },
"using_columns": [...]
}join_type: "INNER", "LEFT", "RIGHT", "FULL", "CROSS", "NATURAL", etc.
{"kind": "ORDER_TERM", "expr": { ... }, "direction": "DESC", "nulls": "FIRST"}{"kind": "LIMIT", "count": { ... }, "offset": { ... }}{"kind": "COLUMN_DEF", "name": "id", "type_name": "INTEGER", "constraints": [...]}{
"kind": "COLUMN_CONSTRAINT",
"constraint_type": "PRIMARY_KEY",
"name": "pk_id",
"sort_order": "ASC",
"conflict_action": "ABORT",
"is_autoinc": true,
"expr": { ... },
"fk": { ... },
"collation": "NOCASE",
"generated_type": "STORED"
}{
"kind": "TABLE_CONSTRAINT",
"constraint_type": "PRIMARY_KEY",
"name": "pk_composite",
"columns": [...],
"expr": { ... },
"fk": { ... },
"conflict_action": "ABORT",
"is_autoinc": false
}{
"kind": "FOREIGN_KEY",
"table": "other",
"columns": [...],
"on_delete": "CASCADE",
"on_update": "SET NULL",
"deferrable": "DEFERRED"
}{
"kind": "CTE",
"name": "cte1",
"columns": [...],
"select": { ... },
"materialized": "MATERIALIZED"
}{"kind": "WITH", "recursive": true, "ctes": [...]}{
"kind": "UPSERT",
"conflict_target": [...],
"conflict_where": { ... },
"set_clauses": [...],
"where": { ... },
"next": { ... }
}{"kind": "RETURNING", "columns": [...]}{
"kind": "WINDOW_DEF",
"name": "w1",
"base_name": "w_base",
"partition_by": [...],
"order_by": [...],
"frame": { ... }
}{
"kind": "WINDOW_FRAME",
"frame_type": "ROWS",
"start": { ... },
"end": { ... },
"exclude": "CURRENT ROW"
}frame_type: "ROWS", "RANGE", "GROUPS".
{"kind": "FRAME_BOUND", "bound_type": "PRECEDING", "expr": { ... }}{"kind": "SET_CLAUSE", "column": "name", "columns": [...], "expr": { ... }}{"kind": "INDEX_COLUMN", "expr": { ... }, "collation": "NOCASE", "sort_order": "ASC"}{"kind": "VALUES_ROW", "values": [...]}{"kind": "TRIGGER_CMD", "stmt": { ... }}