Skip to content

CLI Guide

The JSSON CLI is your gateway to transpiling JSSON files into JSON. Let’s master it! 🚀

The simplest way to use JSSON:

Terminal window
jsson -i input.jsson -o output.json

This reads input.jsson and writes the transpiled JSON to output.json.

FlagShortDescriptionExample
--input-iInput JSSON file (required)-i config.jsson
--output-oOutput file (optional)-o config.json

Without -o: Output is printed to stdout (terminal)

Terminal window
# Print to terminal
jsson -i config.jsson
# Save to file
jsson -i config.jsson -o config.json
# Pipe to another command
jsson -i config.jsson | jq '.app.name'
FlagDescriptionExample
--formatOutput format: json (default)--format json
--prettyPretty-print JSON output--pretty
--compactCompact JSON (no whitespace)--compact
Terminal window
# Pretty-printed JSON (default)
jsson -i config.jsson -o config.json --pretty
# Compact JSON (one line)
jsson -i config.jsson -o config.json --compact
Terminal window
# Show help
jsson --help
jsson -h
# Show version
jsson --version
jsson -v
Terminal window
jsson -i config.jsson -o config.json
Terminal window
jsson -i config.jsson

Perfect for testing your JSSON before committing!

Terminal window
# Use with jq
jsson -i config.jsson | jq '.database.host'
# Count lines
jsson -i config.jsson | wc -l
# Search for a value
jsson -i config.jsson | grep "localhost"

PowerShell:

Terminal window
# Convert all .jsson files in a directory
Get-ChildItem *.jsson | ForEach-Object {
$output = $_.BaseName + ".json"
jsson -i $_.Name -o $output
}

Bash:

Terminal window
# Convert all .jsson files
for file in *.jsson; do
jsson -i "$file" -o "${file%.jsson}.json"
done

PowerShell:

Terminal window
# Simple watch loop
while ($true) {
jsson -i config.jsson -o config.json
Start-Sleep -Seconds 2
}

Bash with entr:

Terminal window
# Auto-transpile on file change
ls *.jsson | entr jsson -i config.jsson -o config.json

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
.PHONY: build clean
build: config.json
config.json: config.jsson
\tjsson -i config.jsson -o config.json
clean:
\trm -f config.json

.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.json

Dockerfile:

FROM golang:1.21-alpine AS builder
WORKDIR /build
COPY . .
RUN go build -o jsson cmd/jsson/main.go
FROM alpine:latest
COPY --from=builder /build/jsson /usr/local/bin/
COPY config.jsson /app/
WORKDIR /app
RUN jsson -i config.jsson -o config.json
CMD ["cat", "config.json"]
CodeMeaning
0Success
1Error (lex, parse, or transpile error)
2Invalid arguments

Example:

Terminal window
jsson -i config.jsson -o config.json
if [ $? -eq 0 ]; then
echo "Success!"
else
echo "Error transpiling JSSON"
exit 1
fi

PowerShell:

Terminal window
try {
jsson -i config.jsson -o config.json
if ($LASTEXITCODE -ne 0) {
throw "JSSON transpilation failed"
}
} catch {
Write-Error $_
exit 1
}

Bash:

Terminal window
if ! jsson -i config.jsson -o config.json 2> errors.log; then
echo "Error: $(cat errors.log)"
exit 1
fi
Terminal window
# Just check if JSSON is valid
jsson -i config.jsson > /dev/null
echo $? # 0 = valid, 1 = error
Terminal window
# See what changed
jsson -i old.jsson > old.json
jsson -i new.jsson > new.json
diff old.json new.json
Terminal window
# Re-format JSON using JSSON
jsson -i config.jsson --pretty > formatted.json
Terminal window
# Development
jsson -i config/dev.jsson -o dist/config.json
# Production
jsson -i config/prod.jsson -o dist/config.json

.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"
done
bash: jsson: command not found

Solution: Add JSSON to your PATH or use the full path:

Terminal window
# Use full path
/path/to/jsson -i config.jsson
# Or add to PATH
export PATH=$PATH:/path/to/jsson
Permission denied: jsson

Solution: Make it executable:

Terminal window
chmod +x jsson
Error: cannot read file: config.jsson

Solution: Check the file exists and path is correct:

Terminal window
ls -la config.jsson # Verify file exists
jsson -i ./config.jsson # Try with ./

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)
}

Master the CLI and integrate JSSON into your workflow! 🎯