jsonlogic2sql includes an interactive REPL (Read-Eval-Print Loop) for testing JSON Logic expressions.
# Build and run
make run
# Or build manually
go build -o bin/repl ./cmd/repl
./bin/replOn startup, the REPL will prompt for an optional schema path. Leave it empty to skip.
jsonlogic> {">": [{"var": "amount"}, 1000]}
SQL: WHERE amount > 1000
jsonlogic> {"and": [{"==": [{"var": "status"}, "active"]}, {">": [{"var": "count"}, 5]}]}
SQL: WHERE (status = 'active' AND count > 5)
| Command | Description |
|---|---|
:help |
Show available commands |
:examples |
Show example JSON Logic expressions |
:dialect |
Change the SQL dialect |
:params |
Toggle parameterized query output (bind placeholders) |
:schema <path> |
Load a schema JSON file for validation |
:file <path> |
Read JSON Logic from a file |
:clear |
Clear the screen |
:quit |
Exit the REPL |
Use :dialect to switch between SQL dialects:
[BigQuery] jsonlogic> :dialect
Select dialect:
1. BigQuery
2. Spanner
3. PostgreSQL
4. DuckDB
5. ClickHouse
Enter choice (1-5): 3
[PostgreSQL] jsonlogic> {"merge": [{"var": "a"}, {"var": "b"}]}
SQL: WHERE (a || b)
The prompt shows the current dialect in brackets.
Use :params to toggle parameterized query mode. When enabled, the output uses bind placeholders instead of inlined literals:
[BigQuery] jsonlogic> :params
Parameterized mode: ON (output uses bind placeholders)
[BigQuery] jsonlogic> {"and": [{"==": [{"var": "status"}, "active"]}, {">": [{"var": "amount"}, 1000]}]}
SQL: WHERE (status = @p1 AND amount > @p2)
Params: [{p1: "active"}, {p2: 1000}]
[BigQuery] jsonlogic> :params
Parameterized mode: OFF (output uses inlined literals)
[BigQuery] jsonlogic> {"and": [{"==": [{"var": "status"}, "active"]}, {">": [{"var": "amount"}, 1000]}]}
SQL: WHERE (status = 'active' AND amount > 1000)
Placeholder styles vary by dialect (@p1 for BigQuery/Spanner/ClickHouse, $1 for PostgreSQL/DuckDB). See Parameterized Queries for details.
In parameterized mode, pattern operators (for example startsWith, endsWith, contains) must keep placeholders outside string literals.
- Correct:
LIKE CONCAT(@p1, '%') - Incorrect:
LIKE '@p1%'
The correct form preserves bind semantics; the incorrect form treats the placeholder text as a literal string.
For JSON Logic expressions larger than terminal line limits (~4KB), use the :file command:
# Save your large JSON to a file
echo '{"and": [...very large JSON...]}' > input.json
# In the REPL, load it with :file
[BigQuery] jsonlogic> :file input.json
SQL: WHERE (...)Use :schema to load a schema file for field validation and type-aware SQL:
[BigQuery] jsonlogic> :schema schema.json
Schema loaded: schema.json
The :examples command shows common JSON Logic patterns:
jsonlogic> :examples
Example JSON Logic expressions:
1. Simple Comparison
JSON: {">": [{"var": "amount"}, 1000]}
SQL: WHERE amount > 1000
2. Equality Check
JSON: {"==": [{"var": "status"}, "active"]}
SQL: WHERE status = 'active'
3. Logical AND
JSON: {"and": [{">": [{"var": "a"}, 10]}, {"<": [{"var": "b"}, 20]}]}
SQL: WHERE (a > 10 AND b < 20)
...
The REPL displays helpful error messages:
jsonlogic> {"unknownOp": [1, 2]}
Error: [E100] at $.unknownOp (operator: unknownOp): unsupported operator: unknownOp
jsonlogic> {invalid json}
Error: [E007]: invalid JSON: invalid character 'i' looking for beginning of object key string
- Use
:examplesfirst - Learn common patterns before writing your own - Check dialect - Some operators generate different SQL per dialect
- Use
:filefor complex JSON - Avoids terminal line limits - Copy SQL output - Use it directly in your database queries
- Getting Started - Basic library usage
- Examples - Comprehensive examples
- Operators - All supported operators