scjson

scjson logo

scjson

A JSON-based serialization of SCXML (State Chart XML) for modern tooling, interoperability, and education.

Execution Engines

JS/TS Harness (via SCION)


Overview

scjson is a structured, schema-based representation of SCXML, the W3C standard for state machine modeling. This format preserves the semantics and hierarchy of SCXML while making it more accessible to modern tools, languages, and interfaces.

Why JSON?


Goals


Schema

The canonical scjson.schema.json file is located in /scjson.schema.json. It is generated from Pydantic models and used to validate all *.scjson documents. Detailed inference rules used by the converters are described in INFERENCE.md.


Directory Structure

Each language implementation lives in its own directory, as a standalone module or library root:

/schema/ → JSON Schema definition of scjson /examples/ → SCXML and scjson sample pairs /tutorial/ → Git submodule: Zhornyak SCXML tutorial /python/ → Python reference implementation (CLI + library) /js/ → JavaScript CLI and library /ruby/ → Ruby CLI and gem /go/ → Go command line utility /rust/ → Rust command line utility /swift/ → Swift command line tool /java/ → Java command line tool /lua/ → Lua scripts /csharp/ → C# command line tool

Each directory is designed to be independently usable as a library or CLI tool.


Converters & Engines

Language Status Path Notes
Python ✅ Canonical py Reference implementation and compatibility baseline
JavaScript ✅ Parity js Matches Python output on the tutorial corpus; harness available via SCION
Ruby ✅ Parity ruby Converter parity; engine trace interface under active development
Rust ✅ Parity rust Matches Python output on the tutorial corpus
Java ✅ Parity java Uses SCION-backed runner; matches Python output
Go ✅ Parity go Matches Python output on the tutorial corpus
Swift ✅ Parity swift Matches Python output on the tutorial corpus
C# ⚠️ Beta csharp Functional CLI; parity work in progress
Lua ✅ Parity lua Matches Python output on the tutorial corpus

See docs/COMPATIBILITY.md for the latest cross-language parity details and test notes.


Examples & Test Suite

This repo includes a curated set of canonical SCXML examples and their equivalent scjson forms in /examples. These are used for:

These examples are derived from and/or adapted from:

📚 Included Tutorial (as Git Submodule)

We include Alex Zhornyak’s SCXML Editor Tutorial as a Git submodule under /tutorial.
This provides a rich set of canonical SCXML test cases and diagrams.

Attribution is provided for educational purposes. No endorsement is implied.
Source: https://alexzhornyak.github.io/ScxmlEditor-Tutorial/


🛠️ Submodule Setup

If you cloned this repo and /tutorial is empty, run:

git submodule init
git submodule update
Or clone with submodules in one step:

git clone --recurse-submodules https://github.com/your-org/scjson.git

This ensures you get the complete tutorial content alongside the examples and converters.


Converters

All converters share the same schema and test suite to ensure compatibility.


Getting Started

# Convert from SCXML to scjson
scjson convert --from scxml path/to/file.scxml --to scjson path/to/file.scjson

# Validate a scjson file
scjson validate path/to/file.scjson

Package Repostory Availability

pypi: [https://pypi.org/project/scjson/]

pip install scjson

npm: [https://www.npmjs.com/package/scjson]

npm install scjson
# harness requires scion-core
npm install scion-core

Harness (Node):

npx scjson-scion-trace -I path/to/chart.scxml -e events.jsonl --xml

rubygems: [https://rubygems.org/gems/scjson]

gem install scjson

RubyGems notes:

cargo: [https://crates.io/crates/scjson]

cargo install scjson

dockerhub: [https://hub.docker.com/r/iraa/scjson] (Full development environment for all supported languages)

docker pull iraa/scjson:latest

For a full example of installing toolchains and dependencies across languages see codex/startup.sh.

Documentation

Known Divergences and Issues

Cross‑engine comparisons sometimes surface intentional, documented differences (e.g., ordering nuances, ECMA in semantics, history re‑entry). Use these resources to understand, normalize, and triage behavior across SCION (Node), Python, and Ruby:

Quick Installs.

Python Module

cd py
pip install -r requirements.txt
pytest -q

JavaScript Module

cd js
npm ci
npm test --silent

Ruby Module

cd ruby
gem install bundler
bundle install
bundle exec rspec

Go Module

cd go
go test ./...
go build

Rust Module

cd rust
cargo test

Swift Module

cd swift
swift test

C# Module

cd csharp
dotnet test -v minimal

Lua Module

cd lua
luarocks install luaexpat --deps-mode=one
luarocks install dkjson --deps-mode=one
luarocks install busted --deps-mode=one
busted tests

All source code in this directory is released under the BSD 1-Clause license. See LICENSE and LEGAL.md for details. Additional documentation is available in AGENTS.md and TESTING.md.