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#
- Standard output carries exactly one JSON document followed by a newline, and nothing else. This holds when the command succeeds and when it fails. Standard error is empty.
- Every document starts with
"format_version": "1.0"and"command", the name of the command. - Every document has
validanddiagnostics.validisfalsewhen any diagnostic has the severity"error". It reflects diagnostics only: a failing test case, orplan -detailed-exitcodeexiting with 2, keeps"valid": true. - Exit codes are the ones the command has without
-json. - Adding a field or a value raises the minor version. Renaming or removing a field, or changing what it means, raises the major version. Read
format_versionfirst. - Strings are UTF-8. A value that StructOp holds as text stays a string in the document; it is never turned into a number.
- Without
-jsonthe text output is unchanged.
Commands that support it#
| Command | Document |
|---|---|
validate -json | the diagnostics of the project |
plan -json | the summary and each change with the abilities that cause it |
show -json | the recorded state; with a saved plan file, the plan document with "command": "show" |
test -json | each test run and the totals |
graph -json | nodes and edges, as an alternative to -format=mermaid and -format=archify |
version -json | the StructOp version and the locked providers |
state -json list, state -json show ADDRESS | the recorded resources |
schema -json | what the providers of the project accept (see below) |
init -json | the 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:
{
"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.