CLI Guide
The JSSON CLI is your gateway to transpiling JSSON files into JSON, YAML, TOML, or TypeScript. Let’s master it! 🚀
Basic Usage
Section titled “Basic Usage”The simplest way to use JSSON:
jsson -i input.jsson > output.jsonThis reads input.jsson and writes the transpiled JSON to output.json using shell redirection.
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 |
--format | -f | Output format (optional, default: json) | -f yaml |
Note: The CLI always prints to stdout (terminal). Use > to save to a file.
# Print to terminaljsson -i config.jsson
# Save to filejsson -i config.jsson > 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), yaml, toml, ts | --format yaml |
# JSON (default)jsson -i config.jsson > config.json
# YAMLjsson -i config.jsson -f yaml > config.yaml
# TOMLjsson -i config.jsson -f toml > config.toml
# TypeScriptjsson -i config.jsson -f ts > config.tsHelp & Version
Section titled “Help & Version”# Show helpjsson --helpjsson -h
# Show versionjsson --versionjsson -vStreaming Options
Section titled “Streaming Options”For large datasets, JSSON supports streaming mode to reduce memory usage:
| Flag | Description | Default |
|---|---|---|
--stream | Enable streaming mode | false |
--stream-threshold | Auto-enable streaming for ranges > N items | 10000 |
# Enable streaming explicitlyjsson -i large-data.jsson --stream > output.json
# Auto-enable for ranges > 5000 itemsjsson -i data.jsson --stream-threshold 5000 > output.json
# Default: auto-enables for ranges > 10,000 itemsjsson -i data.jsson > output.jsonWhen to use streaming:
- Generating 100k+ items
- Large matrix/grid data (100x100+)
- Memory-constrained environments
- Processing millions of records
Performance:
- ✅ 100k items: ~30MB output, < 50MB memory
- ✅ 1M items: Processable without OOM
- ✅ Nested transformations: Optimized
Common Workflows
Section titled “Common Workflows”1. Quick Transpilation
Section titled “1. Quick Transpilation”jsson -i config.jsson > 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 > $output}Bash:
# Convert all .jsson filesfor file in *.jsson; do jsson -i "$file" > "${file%.jsson}.json"done5. Watch for Changes
Section titled “5. Watch for Changes”PowerShell:
# Simple watch loopwhile ($true) { jsson -i config.jsson > config.json Start-Sleep -Seconds 2}Bash with entr:
# Auto-transpile on file changels *.jsson | entr -s 'jsson -i config.jsson > config.json'Integration Examples
Section titled “Integration Examples”NPM Scripts
Section titled “NPM Scripts”package.json:
{ "scripts": { "build:config": "jsson -i config.jsson > 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 jsson -i config.jsson > config.json
clean: rm -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 > 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 > 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 > 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 > config.json if ($LASTEXITCODE -ne 0) { throw "JSSON transpilation failed" }} catch { Write-Error $_ exit 1}Bash:
if ! jsson -i config.jsson > 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 JSSON# (Note: JSSON doesn't parse JSON, but you can use jq for this)cat config.json | jq .4. Environment-Specific Configs
Section titled “4. Environment-Specific Configs”# Developmentjsson -i config/dev.jsson > dist/config.json
# Productionjsson -i config/prod.jsson > 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" > "$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 ./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! 🎯