Go API Reference
You can use JSSON as a library in your Go projects to transpile JSSON content programmatically.
Installation
Section titled “Installation”go get github.com/carlosedujs/jssonBasic Usage
Section titled “Basic Usage”The core package is jsson/internal/transpiler.
package main
import ( "fmt" "jsson/internal/lexer" "jsson/internal/parser" "jsson/internal/transpiler")
func main() { input := ` server { port = 8080 debug = true } `
// 1. Lexer l := lexer.New(input)
// 2. Parser p := parser.New(l) program := p.ParseProgram()
if len(p.Errors()) > 0 { panic(p.Errors()) }
// 3. Transpiler // New(program, workingDir, includeMode, sourceFile) t := transpiler.New(program, ".", "keep", "main.jsson")
// Transpile to JSON (Default) jsonOutput, _ := t.Transpile() fmt.Println(string(jsonOutput))}Transpilation Methods
Section titled “Transpilation Methods”The Transpiler struct provides methods for different output formats:
Transpile()
Section titled “Transpile()”Transpiles the AST to JSON.
output, err := t.Transpile()// output is []byte containing JSONTranspileToYAML()
Section titled “TranspileToYAML()”Transpiles the AST to YAML.
output, err := t.TranspileToYAML()// output is []byte containing YAMLTranspileToTOML()
Section titled “TranspileToTOML()”Transpiles the AST to TOML.
output, err := t.TranspileToTOML()// output is []byte containing TOMLTranspileToTypeScript()
Section titled “TranspileToTypeScript()”Transpiles the AST to TypeScript with type definitions.
output, err := t.TranspileToTypeScript()// output is []byte containing TypeScript codeError Handling
Section titled “Error Handling”All transpile methods return ([]byte, error). You should always check the error returned.
output, err := t.Transpile()if err != nil { log.Fatalf("Transpilation failed: %v", err)}