Skip to content

Extension Json Definitions

Mikołaj Milewski edited this page Oct 27, 2026 · 1 revision

JSON behavior definitions and structural events

Stateflows.Extensions.Json supports declarative State Machine and Activity definitions, as well as JSON-based definitions for structural events and requests. These definitions are parsed into the ordinary Stateflows registration APIs; they do not create a separate runtime or bypass the core behavior rules.

Register definitions

Install Stateflows.Extensions.Json, then parse a JSON document and register it with the corresponding builder:

using Stateflows.Common.Json;
using Stateflows.StateMachines.Json;

var options = new JsonOptions()
    .AddType<PaymentReceived>("events.paymentReceived");

services.AddStateflows(stateflows => stateflows.AddStateMachines(machines =>
    machines.AddStateMachineJson(File.ReadAllText("order.json"), options)));

Use AddActivityJson from Stateflows.Activities.Json to register an Activity. A JsonOptions registry can provide explicit aliases for CLR types referenced by a document; definitions cannot name assemblies, load arbitrary CLR types, or introduce aliases themselves. Structural events should be registered before behaviors that refer to their event names.

The package also provides JsonEventDefinition.Parse(...).Register(...) for structural events and requests. IEventFactory.CreateFromJson decodes an incoming JSON payload against the registered structural event definition; ordinary Stateflows validation still determines whether the event is valid.

Validation and schemas

The parsers reject unknown properties, duplicate JSON properties, invalid shapes, unsupported types, and unresolved or incompatible aliases. Behavior definition binding validates referenced handlers and the expanded behavior graph before registration. JSON parser, schema, binding, data-binding, and expansion diagnostics are reported through the package's definition exception/report types; failed registration does not replace an existing valid definition.

Draft 2020-12 schemas are included in the package:

The schemas help authoring tools, while parsing and registration perform authoritative validation. The package README documents definition shapes, aliases, validation options, structural event payload conversion, and diagnostics in detail.

Overview
Installation
Runtimes
   Orleans runtime
Concepts
   Events and Structural Events
   Messaging Patterns
   Validation
   Scheduling
   Observability
Behaviors
   Behavior Values
   Dependency Injection
   Behavioral Groups
   State Machines
       Concepts
           State Identity
           In-State Event Deferrals
           Evaluation of Transitions
           Exception Handling
       Building blocks
           Regions
           States
               State
               Composite State
               Orthogonal State
               Final State
           Pseudostates
               Choice
               Junction
               Fork
               Join
               History
           Transitions
               Transition
               Default Transition
               Internal Transition
   Activities
       Concepts
           Exception Handling
           Implicit Fork and Join
           Tokens
       Building blocks
           Nodes
               Action Node
               Decision Node
               Merge Node
               Initial Node
               Final Node
               Input Node
               Output Node
               Fork Node
               Join Node
               Accept Event Action Node
               Send Event Action Node
               Publish Event Action Node
               Time Event Action Node
               Data Store Node
               Structured Activity Node
               Iterative Activity Node
               Parallel Activity Node
           Flows
               Data Flow
               Control Flow
   Actions
   Entities
       Fields
       Mutations
       Projections
Extensions
   ClearScript
   FluentValidation
   JSON definitions
   Minimal APIs
   OneOf
   OpenTelemetry
   PlantUML
   Scheduling

Clone this wiki locally