CLI Guide
The JSSON CLI is your gateway to transpiling JSSON files into JSON. Let’s master it! 🚀
Basic Usage
Section titled “Basic Usage”The simplest way to use JSSON:
jsson -i input.jsson -o output.jsonThis reads input.jsson and writes the transpiled JSON to output.json.
Command-Line Flags
Section titled “Command-Line Flags”Input/Output
Section titled “Input/Output”| Flag | Short | Description | Example |
|---|---|---|---|
--input | -i | Input JSSON file (required) | -i config.jsson |
--output | -o | Output file (optional) | -o config.json |
Without -o: Output is printed to stdout (terminal)
# Print to terminaljsson -i config.jsson
# Save to filejsson -i config.jsson -o config.json
# Pipe to another commandjsson -i config.jsson | jq '.app.name'Format Options
Section titled “Format Options”| Flag | Description | Example |
|---|---|---|
--format | Output format: json (default) | --format json |
--pretty | Pretty-print JSON output | --pretty |
--compact | Compact JSON (no whitespace) | --compact |
# Pretty-printed JSON (default)jsson -i config.jsson -o config.json --pretty
# Compact JSON (one line)jsson -i config.jsson -o config.json --compactHelp & Version
Section titled “Help & Version”# Show helpjsson --helpjsson -h
# Show versionjsson --versionjsson -vCommon Workflows
Section titled “Common Workflows”1. Quick Transpilation
Section titled “1. Quick Transpilation”jsson -i config.jsson -o config.json2. Check Output Without Saving
Section titled “2. Check Output Without Saving”jsson -i config.jssonPerfect for testing your JSSON before committing!
3. Pipe to Other Tools
Section titled “3. Pipe to Other Tools”# Use with jqjsson -i config.jsson | jq '.database.host'
# Count linesjsson -i config.jsson | wc -l
# Search for a valuejsson -i config.jsson | grep "localhost"4. Batch Processing
Section titled “4. Batch Processing”PowerShell:
# Convert all .jsson files in a directoryGet-ChildItem *.jsson | ForEach-Object { $output = $_.BaseName + ".json" jsson -i $_.Name -o $output}Bash:
# Convert all .jsson filesfor file in *.jsson; do jsson -i "$file" -o "${file%.jsson}.json"done5. Watch for Changes
Section titled “5. Watch for Changes”PowerShell:
# Simple watch loopwhile ($true) { jsson -i config.jsson -o config.json Start-Sleep -Seconds 2}Bash with entr:
# Auto-transpile on file changels *.jsson | entr jsson -i config.jsson -o config.jsonIntegration Examples
Section titled “Integration Examples”NPM Scripts
Section titled “NPM Scripts”package.json:
{ "scripts": { "build:config": "jsson -i config.jsson -o dist/config.json", "watch:config": "nodemon --watch config.jsson --exec 'npm run build:config'" }}Makefile
Section titled “Makefile”# Makefile.PHONY: build clean
build: config.json
config.json: config.jsson\tjsson -i config.jsson -o config.json
clean:\trm -f config.jsonGitHub Actions
Section titled “GitHub Actions”.github/workflows/build.yml:
name: Build Config
on: [push]
jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2
- name: Download JSSON run: | wget https://github.com/carlosedujs/jsson/releases/latest/download/jsson-linux chmod +x jsson-linux
- name: Transpile JSSON run: ./jsson-linux -i config.jsson -o config.json
- name: Upload artifact uses: actions/upload-artifact@v2 with: name: config path: config.jsonDocker
Section titled “Docker”Dockerfile:
FROM golang:1.21-alpine AS builder
WORKDIR /buildCOPY . .RUN go build -o jsson cmd/jsson/main.go
FROM alpine:latestCOPY --from=builder /build/jsson /usr/local/bin/COPY config.jsson /app/
WORKDIR /appRUN jsson -i config.jsson -o config.json
CMD ["cat", "config.json"]Error Handling
Section titled “Error Handling”Exit Codes
Section titled “Exit Codes”| Code | Meaning |
|---|---|
0 | Success |
1 | Error (lex, parse, or transpile error) |
2 | Invalid arguments |
Example:
jsson -i config.jsson -o config.jsonif [ $? -eq 0 ]; then echo "Success!"else echo "Error transpiling JSSON" exit 1fiCapturing Errors
Section titled “Capturing Errors”PowerShell:
try { jsson -i config.jsson -o config.json if ($LASTEXITCODE -ne 0) { throw "JSSON transpilation failed" }} catch { Write-Error $_ exit 1}Bash:
if ! jsson -i config.jsson -o config.json 2> errors.log; then echo "Error: $(cat errors.log)" exit 1fiTips & Tricks
Section titled “Tips & Tricks”1. Validate Without Output
Section titled “1. Validate Without Output”# Just check if JSSON is validjsson -i config.jsson > /dev/nullecho $? # 0 = valid, 1 = error2. Compare Before/After
Section titled “2. Compare Before/After”# See what changedjsson -i old.jsson > old.jsonjsson -i new.jsson > new.jsondiff old.json new.json3. Format Existing JSON
Section titled “3. Format Existing JSON”# Re-format JSON using JSSONjsson -i config.jsson --pretty > formatted.json4. Environment-Specific Configs
Section titled “4. Environment-Specific Configs”# Developmentjsson -i config/dev.jsson -o dist/config.json
# Productionjsson -i config/prod.jsson -o dist/config.json5. Pre-commit Hook
Section titled “5. Pre-commit Hook”.git/hooks/pre-commit:
#!/bin/bash# Transpile JSSON files before commit
for file in $(git diff --cached --name-only | grep '\.jsson$'); do output="${file%.jsson}.json" jsson -i "$file" -o "$output" git add "$output"doneTroubleshooting
Section titled “Troubleshooting”Command Not Found
Section titled “Command Not Found”bash: jsson: command not foundSolution: Add JSSON to your PATH or use the full path:
# Use full path/path/to/jsson -i config.jsson
# Or add to PATHexport PATH=$PATH:/path/to/jssonPermission Denied
Section titled “Permission Denied”Permission denied: jssonSolution: Make it executable:
chmod +x jssonFile Not Found
Section titled “File Not Found”Error: cannot read file: config.jssonSolution: Check the file exists and path is correct:
ls -la config.jsson # Verify file existsjsson -i ./config.jsson # Try with ./Programmatic Usage (Go)
Section titled “Programmatic Usage (Go)”You can also use JSSON as a Go library:
package main
import ( "fmt" "jsson/internal/lexer" "jsson/internal/parser" "jsson/internal/transpiler")
func main() { input := ` user { name = João age = 25 } `
// Lex l := lexer.New(input)
// Parse p := parser.New(l) program := p.ParseProgram()
// Transpile t := transpiler.New() json, err := t.Transpile(program) if err != nil { panic(err) }
fmt.Println(json)}What’s Next?
Section titled “What’s Next?”- Getting Started — New to JSSON? Start here
- Syntax Reference — Complete syntax guide
- Errors & Debugging — Troubleshooting help
Master the CLI and integrate JSSON into your workflow! 🎯