go-json provides a command-line interface for running, validating, testing, and generating code from JSON programs.
go-json <command> [options]Two CLI variants:
| Binary | Install | Script Runtimes |
|---|---|---|
| Basic | go install github.com/bitcode-framework/go-json/cmd/go-json@latest |
None (core language only) |
| Full | go install github.com/bitcode-framework/go-json-runtimes/cmd/go-json@latest |
goja (.js), quickjs (.js), yaegi (.go), Node.js (.ts/.mjs, auto), Python (.py, auto) |
The "full" variant includes embedded script runtimes so script: imports work out of the box.
| Command | Description |
|---|---|
run |
Execute a go-json program |
serve |
Start a web server from a server program |
check |
Validate a program (compile check, no execution) |
test |
Run test files |
ast |
Export program AST as JSON |
codegen |
Generate Go/JS/Python code from a program |
generate |
Scaffold CRUD, auth, or project from templates |
openapi |
Generate OpenAPI spec from a server program |
migrate |
Migrate deprecated syntax to newer version |
version |
Print version |
help |
Print help |
Execute a go-json program.
go-json run <program.json> [options]| Flag | Default | Description |
|---|---|---|
--input <json> |
— | Inline JSON input |
--input-file <path> |
— | Read input from file |
--timeout <duration> |
30s |
Execution timeout |
--max-depth <n> |
— | Override call depth limit |
--io <modules> |
— | Enable I/O modules (http,fs,sql,exec or all) |
--trace |
false |
Print execution trace |
# Basic execution
go-json run hello.json
# With inline input
go-json run greet.json --input '{"name": "Alice", "age": 30}'
# With input from file
go-json run process.json --input-file data.json
# With I/O modules enabled
go-json run fetch.json --io http
go-json run script.json --io all
# With execution trace
go-json run program.json --trace
# With custom timeout
go-json run long_task.json --timeout 120s
# From stdin (pipe)
echo '{"name": "Bob"}' | go-json run greet.jsonInput is read from exactly one source (mutually exclusive):
--input— inline JSON string--input-file— path to JSON file- stdin — if piped and neither flag is provided
- Program return value is printed to stdout as JSON
- Errors are printed to stderr
- Exit code:
0on success,1on error
Start a web server from a server program (a program with routes).
go-json serve <program.json> [options]| Flag | Default | Description |
|---|---|---|
--port <n> |
3000 |
Listen port |
--host <addr> |
0.0.0.0 |
Listen host |
--dev |
false |
Dev mode (template reload, verbose logging) |
--docs |
false |
Enable Swagger UI at /docs |
--io <modules> |
— | Enable I/O modules |
# Start server
go-json serve api.json
# Custom port
go-json serve api.json --port 8080
# Dev mode with Swagger UI
go-json serve api.json --dev --docs
# With I/O modules
go-json serve api.json --io http,fs,sql| Endpoint | Description |
|---|---|
/health |
Health check (bypasses all middleware) |
/docs |
Swagger UI (when --docs is enabled) |
The server handles SIGINT and SIGTERM for graceful shutdown. Configurable timeout via server.graceful_shutdown (default: 10s).
Validate a program without executing it. Performs full compilation including import resolution, struct validation, and structural checks.
go-json check <program.json> [options]| Flag | Default | Description |
|---|---|---|
--verbose |
false |
Show detailed validation info |
# Basic validation
go-json check program.json
# Verbose output
go-json check program.json --verbose0— program is valid1— compilation errors found
Run test files. Test files are go-json programs with "test": true and a "cases" array.
go-json test <path> [options]| Flag | Default | Description |
|---|---|---|
--filter <pattern> |
— | Run only cases matching pattern |
--verbose |
false |
Show input/output per case |
# Run all tests in directory
go-json test tests/
# Run specific test file
go-json test tests/test_math.json
# Filter by case name
go-json test tests/ --filter "factorial"
# Verbose output
go-json test tests/ --verbose{
"name": "test_math",
"test": true,
"import": {"math": "../functions/math.json"},
"cases": [
{
"_c": "Factorial of 5 is 120",
"call": "math.factorial",
"with": {"n": "5"},
"expect": 120
},
{
"_c": "Factorial of 0 is 1",
"call": "math.factorial",
"with": {"n": "0"},
"expect": 1
}
]
}✓ test_math: Factorial of 5 is 120 (1ms)
✓ test_math: Factorial of 0 is 1 (0ms)
2 passed, 0 failed
| Type | Comparison |
|---|---|
| Object | Deep equality |
| Array | Deep equality with order |
| Float | Tolerance of 1e-9 (so 0.1 + 0.2 vs 0.3 passes) |
| Nil | Result must be nil |
Export the program's Abstract Syntax Tree as JSON.
go-json ast <program.json> [options]| Flag | Default | Description |
|---|---|---|
--output <path> |
stdout | Write AST to file |
--format <fmt> |
json |
Output format (currently only json supported) |
# Print AST to stdout
go-json ast program.json
# Save to file
go-json ast program.json --output ast.jsonGenerate native source code from a go-json program.
go-json codegen <program.json> [options]| Flag | Default | Description |
|---|---|---|
--target <lang> |
go |
Target language: go, javascript, python |
--output <path> |
stdout | Output file path |
--package <name> |
main |
Package name (Go only) |
--framework <name> |
varies | Server framework (for server programs) |
| Language | Default Framework |
|---|---|
| Go | fiber |
| JavaScript | express |
| Python | fastapi |
# Generate Go code
go-json codegen program.json --target go --output program.go
# Generate JavaScript
go-json codegen program.json --target javascript --output program.js
# Generate Python
go-json codegen program.json --target python --output program.py
# Server codegen with specific framework
go-json codegen api.json --target go --framework fiber --output server.go
go-json codegen api.json --target javascript --framework express --output server.jsScaffold projects, CRUD APIs, and auth endpoints.
go-json generate <type> [options]Generate CRUD API for a database table.
| Flag | Description |
|---|---|
--table <name> |
Table name (required) |
--dsn <dsn> |
Database connection string (for introspection) |
--fields <spec> |
Manual field definition (name:string,age:int) |
--auth |
Include JWT auth middleware on write endpoints |
--output <path> |
Output file (default: stdout) |
--dry-run |
Print without writing |
Either --dsn or --fields is required.
# From database introspection
go-json generate crud --table users --dsn "postgres://localhost/mydb"
# Manual fields with auth
go-json generate crud --table users --fields "name:string,email:string,role:string" --auth
# Write to file
go-json generate crud --table users --fields "name:string" --output api.jsonGenerate authentication endpoints (register, login, refresh, me, change-password).
| Flag | Description |
|---|---|
--output <path> |
Output file (default: stdout) |
go-json generate auth
go-json generate auth --output auth.jsonGenerate a full project scaffold.
| Flag | Description |
|---|---|
--name <name> |
Project name (default: my-app) |
--auth |
Include auth scaffold with JWT |
--output <dir> |
Output directory (default: ./<name>) |
go-json generate project my-api
go-json generate project --name my-api --auth --output ./my-api/Generated structure:
my-api/
├── api.json # Main server program
├── templates/ # HTML templates
│ ├── index.html
│ └── content.html
├── public/ # Static files
│ └── index.html
├── migrations/ # SQL migrations (when --auth)
│ └── 001_users.sql
├── .env.example # Environment variables
└── README.md # Project documentation
Generate OpenAPI 3.0 specification from a server program.
go-json openapi <program.json> [options]| Flag | Default | Description |
|---|---|---|
--output <path> |
stdout | Output file path |
# Print to stdout
go-json openapi api.json
# Save to file
go-json openapi api.json --output openapi.jsonMigrate deprecated syntax to a newer version.
go-json migrate <program.json> [options]| Flag | Default | Description |
|---|---|---|
--from <version> |
auto-detect | Source version |
--to <version> |
latest | Target version |
--dry-run |
false |
Show changes without applying |
--output <path> |
in-place | Write to different file |
# Auto-detect and migrate
go-json migrate program.json
# Dry run (preview changes)
go-json migrate program.json --dry-run
# Write to new file
go-json migrate program.json --output migrated.jsonThe migration tool uses JSON-aware key renaming (not blind string replace) and preserves JSONC comments.
| Flag | Description |
|---|---|
--version, -v |
Print version |
--help, -h |
Print help |
| Code | Meaning |
|---|---|
0 |
Success |
1 |
Error (compilation, runtime, or validation failure) |