StructOp Handbook
Contents Examples Commands

Machine-readable output

Add -json after a command and StructOp prints one JSON document instead of text. Scripts, editors and programs that help you write a project can read it without parsing text. The format is version 1.0.

On this page

The contract#

Commands that support it#

CommandDocument
validate -jsonthe diagnostics of the project
plan -jsonthe summary and each change with the abilities that cause it
show -jsonthe recorded state; with a saved plan file, the plan document with "command": "show"
test -jsoneach test run and the totals
graph -jsonnodes and edges, as an alternative to -format=mermaid and -format=archify
version -jsonthe StructOp version and the locked providers
state -json list, state -json show ADDRESSthe recorded resources
schema -jsonwhat the providers of the project accept (see below)
init -jsonthe providers that were installed and the index each came from

apply and destroy print the output of your own program, which would corrupt the document, so they do not accept -json. Run plan -json -out=FILE and then apply FILE. fmt, bind, import, refresh, taint, untaint and environment have no JSON form either.

A usage error produces no document, because none has started: an unknown option, a failing -chdir, -json together with -format, or -json with a state subcommand other than list and show. The command exits with 1 (2 for a failing -chdir), prints a text message on standard error and leaves standard output empty.

Diagnostics and exit codes#

A diagnostic has severity, message, hint and range. hint is the name that text mode offers as Did you mean "..."?. range is { "file", "line", "column" } with the file relative to the project folder. Both are null when they do not apply. A project with a misspelt attribute (mesage for message) gives this document and exit code 1:

structop validate -json
{
    "format_version": "1.0",
    "command": "validate",
    "valid": false,
    "diagnostics": [
        {
            "severity": "error",
            "message": "unknown attribute \"mesage\" in ability.print.Hello",
            "hint": "message",
            "range": {
                "file": "main.st",
                "line": 2,
                "column": 5
            }
        }
    ]
}

Exit codes: 0 when the command succeeds, 1 on an error, and for plan -detailed-exitcode also 2 when there are changes. A failing plan, graph, test, state or show still returns the full shape of its document, with empty changes, nodes and edges, cases or resources.

The schema command#

structop schema -json describes what the providers of your project accept: each kind of ability, its attributes and their types. An editor, a script or an assistant that writes declarations can read it and offer only what is valid, before validate runs.

Graph views#

structop graph -json gives the application graph as nodes and edges: the run order, what each ability depends on, and with -changed and -impact the abilities a change touches. Commands and workflow shows the views.

Full reference and schema files#

The field-by-field reference of every document and the JSON Schema files of format 1.0 are provided to licensed customers and evaluation partners. Ask through the official StructOp project on GitLab, as described under commercial enquiries in the licence.